Michelle DiMarino 6 лет назад
Родитель
Сommit
daa9afb017
4 измененных файлов: 101 добавлений и 28 удалений
  1. 40
    6
      NumberUtilities.java
  2. 31
    4
      TableUtilities.java
  3. 16
    4
      TriangleUtilities.java
  4. 14
    14
      package.bluej

+ 40
- 6
NumberUtilities.java Просмотреть файл

@@ -4,29 +4,63 @@
4 4
 public class NumberUtilities {
5 5
     
6 6
     public static String getRange(int start) {
7
-        return null;
7
+        StringBuilder numberRange = new StringBuilder();
8
+        for (int i = 0; i < start; i++){
9
+            numberRange.append(i);
10
+        }
11
+        return numberRange.toString();
12
+            
13
+        
8 14
     }
9 15
     
10 16
     public static String getRange(int start, int stop) {
11
-        return null;
17
+        StringBuilder numberRange = new StringBuilder();
18
+        for (int i = start; i < stop; i++){
19
+            numberRange.append(i);
20
+        }
21
+        return numberRange.toString();
12 22
     }
13 23
 
14 24
 
15 25
     public static String getRange(int start, int stop, int step) {
16
-        return null;
26
+        StringBuilder numberRange = new StringBuilder();
27
+        for (int i = start; i < stop; i += step){
28
+            numberRange.append(i);
29
+        }
30
+        return numberRange.toString();
17 31
     }
18 32
     
19 33
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
34
+        StringBuilder evenNumberList = new StringBuilder();
35
+        for (int i = start; i < stop; i++){
36
+            if (i%2 == 0){
37
+                evenNumberList.append(i);
38
+            }
39
+        }
40
+        
41
+        return evenNumberList.toString();
21 42
     }
22 43
 
23 44
 
24 45
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
46
+        StringBuilder oddNumberList = new StringBuilder();
47
+        for (int i = start; i < stop; i++){
48
+            if (i%2 != 0){
49
+                oddNumberList.append(i);
50
+            }
26 51
     }
52
+    return oddNumberList.toString();
53
+}
27 54
 
28 55
 
29 56
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
57
+       StringBuilder exponentList = new StringBuilder();
58
+        for (int i = start; i <= stop; i++){
59
+            double exponentResult = Math.pow(i, exponent);
60
+            int convertedResult = (int) exponentResult;
61
+            exponentList.append(convertedResult);
62
+            
63
+        }
64
+            return exponentList.toString();
31 65
     }
32 66
 }

+ 31
- 4
TableUtilities.java Просмотреть файл

@@ -1,15 +1,42 @@
1
- 
2 1
 
3 2
 public class TableUtilities {
4 3
     public static String getSmallMultiplicationTable() {
5
-        return null;
4
+        StringBuilder multiTable = new StringBuilder();
5
+        for (int i = 1; i <= 5; i++){
6
+            for (int h = 1; h <= 5; h++){
7
+                int product = h*i;
8
+                multiTable.append(String.format("%3d |", product));
9
+
10
+            }
11
+            multiTable.append("\n");
12
+        }
13
+        return multiTable.toString();
14
+
6 15
     }
7 16
 
8 17
     public static String getLargeMultiplicationTable() {
9
-        return null;
18
+        StringBuilder multiTable = new StringBuilder();
19
+        for (int i = 1; i <= 10; i++){
20
+            for (int h = 1; h <= 10; h++){
21
+                int product = h*i;
22
+                multiTable.append(String.format("%3d |", product));
23
+
24
+            }
25
+            multiTable.append("\n");
26
+        }
27
+        return multiTable.toString();
10 28
     }
11 29
 
12 30
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
31
+        StringBuilder multiTable = new StringBuilder();
32
+        for (int i = 1; i <= tableSize; i++){
33
+            for (int h = 1; h <= tableSize; h++){
34
+                int product = h*i;
35
+                multiTable.append(String.format("%3d |", product));
36
+
37
+            }
38
+            multiTable.append("\n");
39
+        }
40
+        return multiTable.toString();
14 41
     }
15 42
 }

+ 16
- 4
TriangleUtilities.java Просмотреть файл

@@ -3,19 +3,31 @@
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+        StringBuilder width = new StringBuilder();
7
+        for (int i = 1; i <= numberOfStars; i++){
8
+            width.append("*");
9
+        
10
+        }
11
+        return width.toString(); 
7 12
     }
8 13
     
9 14
     public static String getTriangle(int numberOfRows) {
10
-        return null;
15
+        StringBuilder triangle = new StringBuilder();
16
+        for (int i = 1; i <= numberOfRows; i++){
17
+            for (int h =1; h <= i; h++){
18
+                triangle.append("*");
19
+            }
20
+           triangle.append("\n");
21
+        }
22
+        return triangle.toString();
11 23
     }
12 24
 
13 25
 
14 26
     public static String getSmallTriangle() {
15
-        return null;
27
+        return getTriangle(4);
16 28
     }
17 29
 
18 30
     public static String getLargeTriangle() {
19
-        return null;
31
+        return getTriangle(9);
20 32
     }
21 33
 }

+ 14
- 14
package.bluej Просмотреть файл

@@ -1,26 +1,26 @@
1 1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TableUtilitiesTest
3
+dependency1.to=TableUtilities
4 4
 dependency1.type=UsesDependency
5 5
 dependency2.from=TriangleUtilitiesTest
6 6
 dependency2.to=TriangleUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=NumberUtilitiesTest
9
+dependency3.to=NumberUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
12
-editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
15
-objectbench.height=164
11
+editor.fx.0.height=716
12
+editor.fx.0.width=864
13
+editor.fx.0.x=177
14
+editor.fx.0.y=47
15
+objectbench.height=152
16 16
 objectbench.width=484
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
18
+package.divider.vertical=0.7568807339449541
19
+package.editor.height=488
20 20
 package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
21
+package.editor.x=119
22
+package.editor.y=23
23
+package.frame.height=712
24 24
 package.frame.width=508
25 25
 package.numDependencies=3
26 26
 package.numTargets=6