Elliott Stansbury 6 лет назад
Родитель
Сommit
7ffe56cf88
6 измененных файлов: 166 добавлений и 30 удалений
  1. 55
    7
      NumberUtilities.java
  2. 4
    1
      NumberUtilitiesTest.java
  3. 51
    3
      TableUtilities.java
  4. 35
    4
      TriangleUtilities.java
  5. 6
    0
      TriangleUtilitiesTest.java
  6. 15
    15
      package.bluej

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

@@ -1,32 +1,80 @@
1
- 
1
+import java.lang.Math; 
2 2
 
3 3
 
4 4
 public class NumberUtilities {
5 5
     
6 6
     public static String getRange(int start) {
7
-        return null;
7
+        String answer = "";
8
+        for(int i = 0; i < start; i++){
9
+            String myString = String.valueOf(i);
10
+            answer = answer.concat(myString);
11
+           
12
+        }
13
+        
14
+        return answer;
8 15
     }
9 16
     
10 17
     public static String getRange(int start, int stop) {
11
-        return null;
18
+        String answer = "";
19
+        for(int i = start; i < stop; i++){
20
+           String myString = String.valueOf(i);
21
+           answer = answer.concat(myString); 
22
+         
12 23
     }
24
+    
25
+    return answer;
26
+}
13 27
 
14 28
 
15 29
     public static String getRange(int start, int stop, int step) {
16
-        return null;
30
+        String answer = "";
31
+        
32
+        for(int i = start; i < stop; i += step){
33
+            String myString = String.valueOf(i);
34
+            answer = answer.concat(myString);
35
+        }
36
+        return answer;
17 37
     }
18 38
     
19 39
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
40
+        String answer = "";
41
+        
42
+        for(int i = start; i < stop; i++){
43
+            if(i%2 == 0){
44
+                String myString = String.valueOf(i);
45
+                answer = answer.concat(myString);
46
+            }
47
+        }
48
+        return answer;
21 49
     }
22 50
 
23 51
 
24 52
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
53
+        String answer = "";
54
+        
55
+        for(int i = start; i < stop; i++){
56
+            if(i%2!= 0){
57
+                String myString = String.valueOf(i);
58
+                answer = answer.concat(myString);
59
+            }
60
+        }
61
+        return answer;
26 62
     }
27 63
 
28 64
 
29 65
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
66
+        String answer = "";
67
+        
68
+        for(int i = start; i <= stop; i++){
69
+           int expo = (int) Math.pow(i, exponent);
70
+           String myString = String.valueOf(expo);
71
+           answer = answer.concat(myString);
72
+           
73
+           
74
+           
75
+       
76
+        
31 77
     }
78
+    return answer;
79
+}
32 80
 }

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

@@ -1,4 +1,4 @@
1
- 
1
+
2 2
 
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
@@ -10,6 +10,9 @@ public class NumberUtilitiesTest {
10 10
         // : Given
11 11
         String expected = "012";
12 12
         int stop = 3;
13
+        
14
+       
15
+   
13 16
 
14 17
         // : When
15 18
         String actual = NumberUtilities.getRange(stop);

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

@@ -2,14 +2,62 @@
2 2
 
3 3
 public class TableUtilities {
4 4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+        String answer = "";
6
+        
7
+        
8
+       for(int i=1; i <= 5;i++){
9
+            for(int j=1; j <= 5; j++){
10
+                int multiply = i * j;
11
+                
12
+                
13
+                String myString = String.valueOf(multiply);
14
+                answer = answer.concat(String.format("%3s |", myString));
15
+                
16
+                
17
+            }
18
+            answer = answer.concat("\n");
19
+        }
20
+        System.out.println(answer);
21
+        return answer;
6 22
     }
7 23
 
8 24
     public static String getLargeMultiplicationTable() {
9
-        return null;
25
+        String answer = "";
26
+        
27
+        
28
+       for(int i=1; i <= 10;i++){
29
+            for(int j=1; j <= 10; j++){
30
+                int multiply = i * j;
31
+                
32
+                
33
+                String myString = String.valueOf(multiply);
34
+                answer = answer.concat(String.format("%3s |", myString));
35
+                
36
+                
37
+            }
38
+            answer = answer.concat("\n");
39
+        }
40
+        System.out.println(answer);
41
+        return answer;
10 42
     }
11 43
 
12 44
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
45
+        String answer = "";
46
+        
47
+        
48
+       for(int i=1; i <= tableSize;i++){
49
+            for(int j=1; j <= tableSize; j++){
50
+                int multiply = i * j;
51
+                
52
+                
53
+                String myString = String.valueOf(multiply);
54
+                answer = answer.concat(String.format("%3s |", myString));
55
+                
56
+                
57
+            }
58
+            answer = answer.concat("\n");
59
+        }
60
+        System.out.println(answer);
61
+        return answer;
14 62
     }
15 63
 }

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

@@ -3,19 +3,50 @@
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+        String answer = "";
7
+        for(int i=0; i < numberOfStars; i++){
8
+            
9
+            answer = answer.concat("*");
10
+        
11
+        }
12
+        
13
+        return answer;
7 14
     }
8 15
     
9 16
     public static String getTriangle(int numberOfRows) {
10
-        return null;
17
+        String answer = "";
18
+        for(int i=0; i < numberOfRows;i++){
19
+            for(int j=0; j <= i; j++){
20
+                answer = answer.concat("*");
21
+            }
22
+            answer = answer.concat("\n");
23
+        }
24
+       
25
+        return answer;
11 26
     }
12 27
 
13 28
 
14 29
     public static String getSmallTriangle() {
15
-        return null;
30
+        String answer = "";
31
+        for(int i=0; i < 4;i++){
32
+            for(int j=0; j <= i; j++){
33
+                answer = answer.concat("*");
34
+            }
35
+            answer = answer.concat("\n");
36
+        }
37
+       
38
+        return answer;
16 39
     }
17 40
 
18 41
     public static String getLargeTriangle() {
19
-        return null;
42
+        String answer = "";
43
+        for(int i=0; i < 9;i++){
44
+            for(int j=0; j <= i; j++){
45
+                answer = answer.concat("*");
46
+            }
47
+            answer = answer.concat("\n");
48
+        }
49
+       
50
+        return answer;
20 51
     }
21 52
 }

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

@@ -103,4 +103,10 @@ public class TriangleUtilitiesTest {
103 103
         String actual = TriangleUtilities.getSmallTriangle();
104 104
         Assert.assertEquals(expected, actual);
105 105
     }
106
+
107
+    @Test
108
+    public void test()
109
+    {
110
+    }
106 111
 }
112
+

+ 15
- 15
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
-dependency2.from=TriangleUtilitiesTest
6
-dependency2.to=TriangleUtilities
5
+dependency2.from=NumberUtilitiesTest
6
+dependency2.to=NumberUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=TriangleUtilitiesTest
9
+dependency3.to=TriangleUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
11
+editor.fx.0.height=709
12 12
 editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
15
-objectbench.height=164
13
+editor.fx.0.x=768
14
+editor.fx.0.y=-997
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.7557603686635944
19
+package.editor.height=485
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=207
22
+package.editor.y=23
23
+package.frame.height=709
24 24
 package.frame.width=508
25 25
 package.numDependencies=3
26 26
 package.numTargets=6