Browse Source

Finished the Methods for each of the classes, and all unit tests passed

Saurav Kamath 6 years ago
parent
commit
e0eb79bbce
6 changed files with 196 additions and 144 deletions
  1. 37
    10
      NumberUtilities.java
  2. 4
    0
      NumberUtilitiesTest.java
  3. 77
    107
      README-TableUtilities.md
  4. 30
    4
      TableUtilities.java
  5. 29
    4
      TriangleUtilities.java
  6. 19
    19
      package.bluej

+ 37
- 10
NumberUtilities.java View File

@@ -1,32 +1,59 @@
1
- 
2
-
3 1
 
4 2
 public class NumberUtilities {
5
-    
6
-    public static String getRange(int start) {
7
-        return null;
3
+
4
+    public static String getRange(int stop) {
5
+        String fin = "";
6
+        for(int i = 0; i < stop; i++){
7
+            fin = fin.concat(String.valueOf(i));    
8
+        }
9
+        return fin;
8 10
     }
9 11
     
10 12
     public static String getRange(int start, int stop) {
11
-        return null;
13
+        String fin = "";
14
+        for(int i = start; i < stop; i++){
15
+            fin = fin.concat(String.valueOf(i));
16
+        }
17
+        return fin;
12 18
     }
13 19
 
14 20
 
15 21
     public static String getRange(int start, int stop, int step) {
16
-        return null;
22
+        String fin = "";
23
+        for(int i = start; i < stop; i += step){
24
+            fin = fin.concat(String.valueOf(i));
25
+        }
26
+        return fin;
17 27
     }
18 28
     
19 29
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
30
+        String fin = "";
31
+        for(int i = start; i < stop; i++){
32
+            if(i%2 == 0){
33
+                fin = fin.concat(String.valueOf(i));
34
+            }
35
+        }
36
+        return fin;
21 37
     }
22 38
 
23 39
 
24 40
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
41
+        String fin = "";
42
+        for(int i = start; i < stop; i++){
43
+            if(i%2 != 0){
44
+                fin = fin.concat(String.valueOf(i));
45
+            }
46
+        }
47
+        return fin;
48
+
26 49
     }
27 50
 
28 51
 
29 52
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
53
+        String fin = "";
54
+        for(int i = start; i <= stop; i++){
55
+            fin = fin.concat(String.valueOf(Math.round(Math.pow(i, exponent))));
56
+        }
57
+        return fin;
31 58
     }
32 59
 }

+ 4
- 0
NumberUtilitiesTest.java View File

@@ -196,4 +196,8 @@ public class NumberUtilitiesTest {
196 196
         // : Then
197 197
         Assert.assertEquals(expected, actual);
198 198
     }
199
+
199 200
 }
201
+
202
+
203
+

+ 77
- 107
README-TableUtilities.md View File

@@ -5,41 +5,11 @@
5 5
     * `String getMultiplicationTable(int width)`
6 6
 
7 7
 
8
-
9
-
10
-    
11
-    
12
-    
13
-    
14
-    
15
-    
16
-    
17
-    
18
-    
19
-    
20
-    
21
-    
22
-    
23
-    
24
-    
25
-    
26
-    
27
-    
28
-    
29
-    
30
-    
31
-    
32
-
33
-
34
-
35
-
36
-
37
-
38 8
 <br><br><br><br>
39 9
 ## `String getSmallMultiplicationTable()`
40 10
 * **Description**
41 11
     * Generate a `String` representation of a multiplication table whose dimensions are `4` by `4`
42
-	
12
+
43 13
 ### Example 1
44 14
 * Sample Script
45 15
 
@@ -47,7 +17,7 @@
47 17
     // : Given    
48 18
     // : When
49 19
     String outcome = TableUtilities.getSmallMultiplicationTable();
50
-    
20
+
51 21
     // : Then
52 22
     System.out.println(outcome);
53 23
     ```
@@ -69,45 +39,45 @@
69 39
 
70 40
 
71 41
 
72
-    
73
-    
74
-    
75
-    
76
-    
77
-    
78
-    
79
-    
80
-    
81
-    
82
-    
83
-    
84
-    
85
-    
86
-    
87
-    
88
-    
89
-    
90
-    
91
-    
92
-    
93
-    
94
-    
95
-    
96
-    
97
-    
98
-    
99
-    
100
-    
101
-    
102
-    
103
-    
104
-    
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
105 75
 <br><br><br><br>
106 76
 ## `String getLargeMultiplicationTable()`
107 77
 * **Description**
108 78
     * Generate a `String` representation of a multiplication table whose dimensions are `9` by `9`
109 79
 
110
-	
80
+
111 81
 ### Example
112 82
 * Sample Script
113 83
 
@@ -115,7 +85,7 @@
115 85
     // : Given    
116 86
     // : When
117 87
     String outcome = TableUtilities.getLargeMultiplicationTable();
118
-    
88
+
119 89
     // : Then
120 90
     System.out.println(outcome);
121 91
     ```
@@ -136,57 +106,57 @@
136 106
     9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
137 107
    10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |
138 108
     ```
139
-    
140
-    
141
-    
142
-    
143
-    
144
-    
145
-    
146
-    
147
-    
148
-    
149
-    
150
-    
151
-    
152
-    
153
-    
154
-    
155
-    
156
-    
157
-    
158
-    
159
-    
160
-    
161
-    
162
-    
163
-    
164
-    
165
-    
166
-    
167
-    
168
-    
169
-    
170
-    
171
-    
172
-    
173
-    
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
174 144
 <br><br><br><br>
175 145
 ## `String getMultiplicationTable(int width)`
176 146
 * **Description**
177 147
     * Given one integer, `width`, generate a `String` representation of a multiplication table whose dimensions are `width` by `width`
178 148
 
179
-	
149
+
180 150
 ### Example 1
181 151
 * Sample Script
182 152
 
183 153
     ```
184 154
     // : Given
185 155
     int n = 3;
186
-    
156
+
187 157
     // : When
188 158
     String outcome = TableUtilities.getMultiplicationTable(n);
189
-    
159
+
190 160
     // : Then
191 161
     System.out.println(outcome);
192 162
     ```
@@ -209,10 +179,10 @@
209 179
     ```
210 180
     // : Given
211 181
     int n = 6;
212
-    
182
+
213 183
     // : When
214 184
     String outcome = TableUtilities.getMultiplicationTable(n);
215
-    
185
+
216 186
     // : Then
217 187
     System.out.println(outcome);
218 188
     ```

+ 30
- 4
TableUtilities.java View File

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

+ 29
- 4
TriangleUtilities.java View File

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

+ 19
- 19
package.bluej View File

@@ -1,27 +1,27 @@
1 1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TriangleUtilitiesTest
3
+dependency1.to=TriangleUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=TriangleUtilitiesTest
6
-dependency2.to=TriangleUtilities
5
+dependency2.from=TableUtilitiesTest
6
+dependency2.to=TableUtilities
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
16
-objectbench.width=484
11
+editor.fx.0.height=1080
12
+editor.fx.0.width=1430
13
+editor.fx.0.x=-319
14
+editor.fx.0.y=-1080
15
+objectbench.height=92
16
+objectbench.width=462
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
20
-package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
24
-package.frame.width=508
18
+package.divider.vertical=0.9051724137931034
19
+package.editor.height=938
20
+package.editor.width=360
21
+package.editor.x=1115
22
+package.editor.y=-1080
23
+package.frame.height=1080
24
+package.frame.width=486
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true