Connor Dunnigan 6 лет назад
Родитель
Сommit
3359fc1b24
4 измененных файлов: 138 добавлений и 29 удалений
  1. 53
    7
      NumberUtilities.java
  2. 33
    3
      TableUtilities.java
  3. 37
    4
      TriangleUtilities.java
  4. 15
    15
      package.bluej

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

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

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

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

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

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

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

@@ -1,27 +1,27 @@
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 11
 editor.fx.0.height=722
12 12
 editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
15
-objectbench.height=164
16
-objectbench.width=484
13
+editor.fx.0.x=480
14
+editor.fx.0.y=23
15
+objectbench.height=174
16
+objectbench.width=571
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
20
-package.editor.width=382
18
+package.divider.vertical=0.7253414264036419
19
+package.editor.height=471
20
+package.editor.width=469
21 21
 package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
24
-package.frame.width=508
22
+package.editor.y=23
23
+package.frame.height=717
24
+package.frame.width=595
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true
@@ -66,7 +66,7 @@ target5.height=50
66 66
 target5.name=NumberUtilitiesTest
67 67
 target5.showInterface=false
68 68
 target5.type=UnitTestTargetJunit4
69
-target5.width=120
69
+target5.width=150
70 70
 target5.x=110
71 71
 target5.y=40
72 72
 target6.association=TriangleUtilitiesTest