Leon il y a 6 ans
Parent
révision
5798030bbf
25 fichiers modifiés avec 838 ajouts et 328 suppressions
  1. 240
    0
      README-NumberUtilities.md
  2. 60
    0
      README-TableUtilities.md
  3. 156
    0
      README-TriangleUtilities.md
  4. 23
    169
      README.md
  5. 5
    0
      pom.xml
  6. 0
    9
      src/main/java/io/zipcoder/microlabs/mastering_loops/CarRide.java
  7. 11
    0
      src/main/java/io/zipcoder/microlabs/mastering_loops/MainApp.java
  8. 38
    0
      src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java
  9. 0
    30
      src/main/java/io/zipcoder/microlabs/mastering_loops/Numbers.java
  10. 0
    17
      src/main/java/io/zipcoder/microlabs/mastering_loops/Shapes.java
  11. 22
    0
      src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java
  12. 29
    0
      src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java
  13. 0
    9
      src/test/java/io/zipcoder/microlabs/mastering_loops/CarRideTest.java
  14. 112
    0
      src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java
  15. 0
    66
      src/test/java/io/zipcoder/microlabs/mastering_loops/NumbersTest.java
  16. 0
    28
      src/test/java/io/zipcoder/microlabs/mastering_loops/ShapesTest.java
  17. 70
    0
      src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java
  18. 72
    0
      src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java
  19. BIN
      target/classes/io/zipcoder/microlabs/mastering_loops/MainApp.class
  20. BIN
      target/classes/io/zipcoder/microlabs/mastering_loops/NumberUtilities.class
  21. BIN
      target/classes/io/zipcoder/microlabs/mastering_loops/TableUtilities.class
  22. BIN
      target/classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.class
  23. BIN
      target/test-classes/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.class
  24. BIN
      target/test-classes/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.class
  25. BIN
      target/test-classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.class

+ 240
- 0
README-NumberUtilities.md Voir le fichier

@@ -0,0 +1,240 @@
1
+# NumberUtilities
2
+
3
+## `String getRange(int stop)`
4
+* **Description**
5
+    * Given an integer, `stop`, return a `String` concatenation of all values between `0` and `stop` exclusively.
6
+### Example
7
+* Sample Script
8
+
9
+    ```
10
+    // : Given
11
+    int stop = 11;
12
+    
13
+    // : When
14
+    String outcome = StringLoops.getRange(stop);
15
+    
16
+    // : Then
17
+    System.out.println(outcome);
18
+    ```
19
+
20
+
21
+
22
+* Sample Output
23
+
24
+    ```
25
+    012345678910
26
+    ```
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+<br><br><br><br>
37
+## `String getRange(int start, int stop)`
38
+* **Description**
39
+    * Given two integers, `start`, and `stop`, return a `String` concatenation of all values between `start` and `stop` exclusively.
40
+### Example
41
+* Sample Script
42
+
43
+    ```
44
+    // : Given
45
+    int start = 5;
46
+    int stop = 11;
47
+    
48
+    // : When
49
+    String outcome = StringLoops.getRange(start, stop);
50
+    
51
+    // : Then
52
+    System.out.println(outcome);
53
+    ```
54
+
55
+
56
+
57
+* Sample Output
58
+
59
+    ```
60
+    5678910
61
+    ```
62
+
63
+
64
+
65
+
66
+
67
+<br><br><br><br>
68
+## `String getRange(int start, int stop, int step)`
69
+* **Description**
70
+    * Given three integers, `start`, `stop`, and `step` return a `String` concatenation of all values between `start` and `stop` exclusively incrementing by `step`.
71
+### Example
72
+* Sample Script
73
+
74
+    ```
75
+    // : Given
76
+    int start = 5;
77
+    int stop = 20;
78
+    int step = 5;
79
+    
80
+    // : When
81
+    String outcome = StringLoops.getRange(min, max, step);
82
+    
83
+    // : Then
84
+    System.out.println(outcome);
85
+    ```
86
+
87
+
88
+
89
+* Sample Output
90
+
91
+    ```
92
+    51015
93
+    ```
94
+    
95
+    
96
+    
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+<br><br><br><br>
108
+## `String getEvenNumbers(int start, int stop)`
109
+* **Description**
110
+    * Given two integers, `start`, and `stop`, return a `String` concatenation of all even values between `start` and `stop` exclusively.
111
+### Example
112
+* Sample Script
113
+
114
+    ```
115
+    // : Given
116
+    int start = 5;
117
+    int stop = 20;
118
+    
119
+    // : When
120
+    String outcome = StringLoops.getOddNumbers(min, max);
121
+    
122
+    // : Then
123
+    System.out.println(outcome);
124
+    ```
125
+
126
+
127
+
128
+* Sample Output
129
+
130
+    ```
131
+    681012141618
132
+    ```
133
+    
134
+
135
+<br><br><br><br>
136
+## `String getOddNumbers(int start, int stop)`
137
+* **Description**
138
+    * Given two integers, `start`, and `stop`, return a `String` concatenation of all even values between `start` and `stop` exclusively.
139
+### Example
140
+* Sample Script
141
+
142
+    ```
143
+    // : Given
144
+    int start = 5;
145
+    int stop = 20;
146
+    
147
+    // : When
148
+    String outcome = StringLoops.getOddNumbers(min, max);
149
+    
150
+    // : Then
151
+    System.out.println(outcome);
152
+    ```
153
+
154
+
155
+
156
+* Sample Output
157
+
158
+    ```
159
+    5791113151719
160
+    ```
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+    
175
+
176
+<br><br><br><br>
177
+## `String getSquareNumbers(int start, int stop)`
178
+* **Description**
179
+    * Given two integers, `start`, and `stop`, return a `String` concatenation of all values squared between `start` and `stop` exclusively.
180
+### Example
181
+* Sample Script
182
+
183
+    ```
184
+    // : Given
185
+    int start = 5;
186
+    int stop = 20;
187
+    
188
+    // : When
189
+    String outcome = StringLoops.getOddNumbers(min, max);
190
+    
191
+    // : Then
192
+    System.out.println(outcome);
193
+    ```
194
+
195
+
196
+
197
+* Sample Output
198
+
199
+    ```
200
+    25100225
201
+    ```
202
+    
203
+    
204
+    
205
+    
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+<br><br><br><br>
214
+## `String getExponentiations(int start, int stop, int step, int exponent)`
215
+* **Description**
216
+    * Given four integers, `start`, `stop`, `step`, and `exponent`, return a `String` concatenation of all values, raised to the specified `exponent`, between `start` and `stop` exclusively, incrementing by the specified `step`.
217
+### Example
218
+* Sample Script
219
+
220
+    ```
221
+    // : Given
222
+    int start = 5;
223
+    int stop = 20;
224
+    int step = 2;
225
+    int exponent = 2;
226
+    
227
+    // : When
228
+    String outcome = StringLoops.getOddNumbers(min, max);
229
+    
230
+    // : Then
231
+    System.out.println(outcome);
232
+    ```
233
+
234
+
235
+
236
+* Sample Output
237
+
238
+    ```
239
+    25100225
240
+    ```

+ 60
- 0
README-TableUtilities.md Voir le fichier

@@ -0,0 +1,60 @@
1
+# TableUtilities
2
+
3
+## `String tableSquare(int n)`
4
+* **Description**
5
+    * Given one integer, `n`, generate a `String` representation of a multiplication table whose dimensions are `n` by `n`
6
+
7
+	
8
+### Example 1
9
+* Sample Script
10
+
11
+    ```
12
+    // : Given
13
+    int n = 4;
14
+    
15
+    // : When
16
+    String outcome = Tables.getMultiplicationTable(n);
17
+    
18
+    // : Then
19
+    System.out.println(outcome);
20
+    ```
21
+
22
+
23
+
24
+* Sample Output
25
+
26
+    ```
27
+    |  1 |  2 |  3 |  4 |
28
+    |  2 |  4 |  6 |  8 |
29
+    |  3 |  6 |  9 | 12 |
30
+    |  4 |  8 | 12 | 16 |
31
+    ```
32
+
33
+
34
+
35
+### Example 2
36
+* Sample Script
37
+
38
+    ```
39
+    // : Given
40
+    int n = 6;
41
+    
42
+    // : When
43
+    String outcome = Tables.getMultiplicationTable(n);
44
+    
45
+    // : Then
46
+    System.out.println(outcome);
47
+    ```
48
+
49
+
50
+
51
+* Sample Output
52
+
53
+    ```
54
+    | 1 |  2 |  3 |  4 |  5 |  6 |
55
+    | 2 |  4 |  6 |  8 | 10 | 12 |
56
+    | 3 |  6 |  9 | 12 | 15 | 18 |
57
+    | 4 |  8 | 12 | 16 | 20 | 24 |
58
+    | 5 | 10 | 15 | 20 | 25 | 30 |
59
+    | 6 | 12 | 18 | 24 | 30 | 36 |
60
+    ```

+ 156
- 0
README-TriangleUtilities.md Voir le fichier

@@ -0,0 +1,156 @@
1
+# TriangleUtilities
2
+## `String getRow(int width)`
3
+* **Description**
4
+    * In the class, `Triangles` Write a method that returns a `String` representation of a row of asterisks whose length is equal to the `width` specified.
5
+    
6
+### Example
7
+* Sample Script
8
+
9
+    ```
10
+    // : Given
11
+    int width = 10;
12
+    
13
+    // : When
14
+    String outcome = Triangles.getRow(width);
15
+    
16
+    // : Then
17
+    System.out.println(outcome);
18
+    ```
19
+
20
+
21
+
22
+* Sample Output
23
+
24
+    ```
25
+    **********
26
+    ```
27
+    
28
+    
29
+    
30
+    
31
+    
32
+    
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+<br><br><br><br>
42
+## `String getSmallTriangle()`
43
+* **Description**
44
+    * In the class, `Triangles` Write a method that returns a `String` representation of a small triangle, whose base height and base width is 4 asterisks.
45
+    
46
+### Example
47
+* Sample Script
48
+
49
+    ```
50
+    // : Given
51
+    // : When
52
+    String outcome = Triangles.getSmallTriangle();
53
+    
54
+    // : Then
55
+    System.out.println(outcome);
56
+    ```
57
+
58
+
59
+
60
+* Sample Output
61
+
62
+    ```
63
+    *
64
+    **
65
+    ***
66
+    ****
67
+    
68
+    ```
69
+    
70
+    
71
+    
72
+    
73
+    
74
+    
75
+
76
+<br><br><br><br>
77
+## `String getLargeTriangle()`
78
+* **Description**
79
+    * Write a method that returns a `String` representation of a large triangle, whose base height and base width is 10 asterisks.
80
+    
81
+### Example
82
+* Sample Script
83
+
84
+    ```
85
+    // : Given
86
+    // : When
87
+    String outcome = Triangles.getLargeTriangle();
88
+    
89
+    // : Then
90
+    System.out.println(outcome);
91
+    ```
92
+
93
+
94
+
95
+* Sample Output
96
+
97
+    ```
98
+    *
99
+    **
100
+    ***
101
+    ****
102
+    *****
103
+    ******
104
+    *******
105
+    ********
106
+    *********
107
+    
108
+    ```
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+<br><br><br><br>
117
+## `String getTriangle(int n)`
118
+* **Description**
119
+    * Given one integer, `n`, generate a `String` representation of a triangle whose base height and width is equal to `n`.
120
+
121
+	
122
+### Example
123
+* Sample Script
124
+
125
+    ```
126
+    // : Given
127
+    int numberOfRows = 15;
128
+    
129
+    // : When
130
+    String outcome = Triangles.createTriangle(numberOfRows);
131
+    
132
+    // : Then
133
+    System.out.println(outcome);
134
+    ```
135
+
136
+
137
+
138
+* Sample Output
139
+
140
+    ```
141
+    *
142
+    **
143
+    ***
144
+    ****
145
+    *****
146
+    ******
147
+    *******
148
+    ********
149
+    *********
150
+    **********
151
+    ***********
152
+    ************
153
+    *************
154
+    **************
155
+    
156
+    ```

+ 23
- 169
README.md Voir le fichier

@@ -1,171 +1,25 @@
1 1
 # ZCW-MicroLabs-Loops
2
+## 1) NumberUtilities
3
+## 2) TriangleUtilities
4
+## 3) TableUtilities
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
2 25
 
3
-## 1) 1 to 10
4
-In the class **Numbers**, complete the method called **oneToTen()** so that it returns a string of the numbers 1 to 10. The Unit Test is provided for you.
5
-
6
-### Example<br>
7
-1: oneToTen()<br>
8
-2: *** Output ***<br>
9
-3: 0<br>
10
-4: 2<br>
11
-5: 3<br>
12
-6: 4<br>
13
-7: 5<br>
14
-8: 6<br>
15
-9: 7<br>
16
-10: 8<br>
17
-11: 9<br>
18
-12: 10
19
-
20
-## 2) Odd Numbers
21
-In the class **Numbers**, complete the method called **oddNumbers()** so that it returns a string of the positive odd numbers less than 20. The Unit Test is not provided for you, you must complete it.
22
-
23
-### Example<br>
24
-1: oddNumbers()<br>
25
-2: *** Output *** <br>
26
-3: 1<br>
27
-4: 3<br>
28
-5: 5<br>
29
-6: 7<br>
30
-7: 9<br>
31
-8: 11<br>
32
-9: 13<br>
33
-10: 15<br>
34
-11: 17<br>
35
-12: 19<br>
36
-
37
-## 3) Square Numbers
38
-In the class **Numbers**, complete the method called **squares()** so that it returns a string of the square numbers up to 100. The Unit Test is not provided for you, you must complete it.
39
-
40
-### Example<br>
41
-1: squares()<br>
42
-2: *** Output *** <br>
43
-3: 1<br>
44
-4: 4<br>
45
-5: 9<br>
46
-6: 16<br>
47
-7: 25<br>
48
-8: 36<br>
49
-9: 49<br>
50
-10: 64<br>
51
-11: 81<br>
52
-12: 100<br>
53
-
54
-
55
-~## 4) Random Numbers~ `// this problem is under maintainence; attempt at your own discretion.`
56
-In the class **Numbers**, complete the method called **random4()** so that it returns a string of out four random integers between 0 and 9. The Unit Test is not provided for you, you must complete it.
57
-
58
-### Example<br>
59
-1: random4()<br>
60
-2: *** Output *** <br>
61
-3: 3<br>
62
-4: 5<br>
63
-5: 2<br>
64
-6: 8<br>
65
-
66
-## 5) Even Numbers < n
67
-
68
-In the class **Numbers**, complete the method called **even()** so that it returns a string of the positive even numbers less than n. The Unit Test is not provided for you, you must complete it.
69
-
70
-### Example<br>
71
-1: even(20)<br>
72
-2: *** Output *** <br>
73
-3: 2<br>
74
-4: 4<br>
75
-5: 6<br>
76
-6: 8<br>
77
-7: 10<br>
78
-8: 12<br>
79
-9: 14<br>
80
-10: 16<br>
81
-11: 18<br>
82
-
83
-## 6) Powers of 2
84
-
85
-In the class **Numbers**, complete the method called **powers()** so that it returns a string of out the powers of 2 from 2^1 up to to 2^n. The Unit Test is not provided for you, you must complete it.
86
-
87
-### Example<br>
88
-1: powers(8)<br>
89
-2: *** Output *** <br>
90
-3: 2<br>
91
-4: 4<br>
92
-5: 8<br>
93
-6: 16<br>
94
-7: 32<br>
95
-8: 64<br>
96
-9: 128<br>
97
-10: 256<br>
98
-
99
-## 7) Are we there yet?
100
-* Modify method `areWeThereYet` in the class `CarRide`.
101
-	* This method should  return `"Good!"` when receiving an argument of `"Yes"`.
102
-* Create class `CarRideTest`
103
-	* Create method `testAreWeThereYet1`
104
-		* The method should ensure the `areWeThereYet` method returns `"Good!"` upon passing an arugment of `"Yes"`.
105
-
106
-	* Create method `testAreWeThereYet2`
107
-		* The method should ensure the `areWeThereYet` method does not return `"Good!"` when receving an argument that is not `"Yes"`.
108
-
109
-* Create class `MainApplication`
110
-	* Using the `CarRide` class, continually prompt the user for input until they response with `"Yes"`.
111
-	* Upon termination, the application should display the value returned from invokation of `areWeThereYet`.
112
-
113
-
114
-### Sample Console Output<br>
115
-```
116
-1: Are we there yet?
117
-2: No
118
-3: Are we there yet?
119
-4: Spoons
120
-5: Are we there yet?
121
-6: Yes
122
-7: Good!
123
-```
124
-
125
-## 8) Triangle
126
-
127
-In the class **Shapes**, complete the method called **triangle()** so that it uses nested loops to produce the following pattern . The Unit Test is not provided for you, you must complete it.
128
-
129
-### Example<br>
130
-1: triangle()<br>
131
-2: *** Output *** <br>
132
-3: * <br>
133
-4: ** <br>
134
-5: *** <br>
135
-6: **** <br>
136
-7: ***** <br>
137
-
138
-## 9) Table Square
139
-
140
-In the class **Shapes**, complete the method called **tableSquare()** so that it uses nested loops to produce a 4x4 table square. The Unit Test is not provided for you, you must complete it.
141
-
142
-### Example<br>
143
-tableSquare()<br>
144
-*** Output *** <br>
145
-A 4 x 4 table square<br>
146
-
147
- ```
148
-|  1 |  2 |  3 |  4 |
149
-|  2 |  4 |  6 |  8 |
150
-|  3 |  6 |  9 | 12 |
151
-|  4 |  8 | 12 | 16 |
152
- ```
153
-
154
- ## 10) Table Squares
155
-
156
- In the class **Shapes**, extend your answer to the last question produce a method that will return string of characters out og ***n x n*** table square. The Unit Test is not provided for you, you must complete it.
157
-
158
-### Example<br>
159
- tableSquares(6)<br>
160
- *** Output *** <br>
161
- A 6 x 6 table square<br>
162
- 
163
- ```
164
-| 1 |  2 |  3 |  4 |  5 |  6 |
165
-| 2 |  4 |  6 |  8 | 10 | 12 |
166
-| 3 |  6 |  9 | 12 | 15 | 18 |
167
-| 4 |  8 | 12 | 16 | 20 | 24 |
168
-| 5 | 10 | 15 | 20 | 25 | 30 |
169
-| 6 | 12 | 18 | 24 | 30 | 36 |
170
-```
171
- 

+ 5
- 0
pom.xml Voir le fichier

@@ -17,4 +17,9 @@
17 17
         </dependency>
18 18
 
19 19
     </dependencies>
20
+
21
+    <properties>
22
+        <maven.compiler.source>1.8</maven.compiler.source>
23
+        <maven.compiler.target>1.8</maven.compiler.target>
24
+    </properties>
20 25
 </project>

+ 0
- 9
src/main/java/io/zipcoder/microlabs/mastering_loops/CarRide.java Voir le fichier

@@ -1,9 +0,0 @@
1
-package io.zipcoder.microlabs.mastering_loops;
2
-
3
-public class CarRide {
4
-
5
-    public String areWeThereYetTest(){
6
-        return "";
7
-    }
8
-
9
-}

+ 11
- 0
src/main/java/io/zipcoder/microlabs/mastering_loops/MainApp.java Voir le fichier

@@ -0,0 +1,11 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+import java.util.Scanner;
4
+
5
+/**
6
+ * Created by leon on 1/31/18.
7
+ */
8
+public class MainApp {
9
+    public static void main(String[] args) {
10
+    }
11
+}

+ 38
- 0
src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java Voir le fichier

@@ -0,0 +1,38 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+
4
+public class NumberUtilities {
5
+    public static String getEvenNumbers(int start, int stop) {
6
+        int offset = start % 2 != 0 ? 0 : 1;
7
+        return getRange(start+offset, stop, 2);
8
+    }
9
+
10
+
11
+    public static String getOddNumbers(int start, int stop) {
12
+        int offset = start % 2 == 0 ? 0 : 1;
13
+        return getRange(start+offset, stop, 2);
14
+    }
15
+
16
+
17
+    public static String getSquareNumbers(int start, int stop, int step) {
18
+        return getExponentiations(start, stop, step, 2);
19
+    }
20
+
21
+
22
+    public static String getRange(int start, int stop, int step) {
23
+        String result = "";
24
+        for (int i = start; i < stop; i += step) {
25
+            result += i;
26
+        }
27
+        return result;
28
+    }
29
+
30
+
31
+    public static String getExponentiations(int start, int stop, int step, int exponent) {
32
+        String result = "";
33
+        for (int i = start; i < stop; i += step) {
34
+            result += (int) Math.pow(i, exponent);
35
+        }
36
+        return result;
37
+    }
38
+}

+ 0
- 30
src/main/java/io/zipcoder/microlabs/mastering_loops/Numbers.java Voir le fichier

@@ -1,30 +0,0 @@
1
-package io.zipcoder.microlabs.mastering_loops;
2
-
3
-
4
-public class Numbers {
5
-
6
-    public String oneToTen(){
7
-        return "";
8
-    }
9
-
10
-    public String oddNumbers(){
11
-        return "";
12
-    }
13
-
14
-    public String squares(){
15
-        return "";
16
-    }
17
-
18
-    public String random4(){
19
-        return "";
20
-    }
21
-
22
-    public String even(int n){
23
-        return "";
24
-    }
25
-
26
-    public String powers(int n){
27
-        return "";
28
-    }
29
-
30
-}

+ 0
- 17
src/main/java/io/zipcoder/microlabs/mastering_loops/Shapes.java Voir le fichier

@@ -1,17 +0,0 @@
1
-package io.zipcoder.microlabs.mastering_loops;
2
-
3
-
4
-public class Shapes {
5
-
6
-    public String triangle(){
7
-        return "";
8
-    }
9
-
10
-    public String tableSquare(){
11
-        return "";
12
-    }
13
-
14
-    public String tableSquares(int n){
15
-        return "";
16
-    }
17
-}

+ 22
- 0
src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java Voir le fichier

@@ -0,0 +1,22 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+public class TableUtilities {
4
+    public static String getSmallMultiplicationTable() {
5
+        return getMultiplicationTable(5);
6
+    }
7
+
8
+    public static String getLargeMultiplicationTable() {
9
+        return getMultiplicationTable(10);
10
+    }
11
+
12
+    public static String getMultiplicationTable(int tableSize) {
13
+        String result = "";
14
+        for (int i = 1; i <= tableSize; i++) {
15
+            for (int j = 1; j <= tableSize; j++) {
16
+                result += String.format("%3d |", i * j);
17
+            }
18
+            result += "\n";
19
+        }
20
+        return result;
21
+    }
22
+}

+ 29
- 0
src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java Voir le fichier

@@ -0,0 +1,29 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+public class TriangleUtilities {
4
+
5
+    public static String getTriangle(int numberOfRows) {
6
+        String result = "";
7
+        for(int i=1; i<numberOfRows; i++) {
8
+            result += getRow(i) + "\n";
9
+        }
10
+        return result;
11
+    }
12
+
13
+    public static String getRow(int numberOfStars) {
14
+        String result = "";
15
+        for(int k=0; k<numberOfStars; k++) {
16
+            result += "*";
17
+        }
18
+        return result;
19
+    }
20
+
21
+    public static String getSmallTriangle() {
22
+        return getTriangle(5);
23
+    }
24
+
25
+
26
+    public static String getLargeTriangle() {
27
+        return getTriangle(10);
28
+    }
29
+}

+ 0
- 9
src/test/java/io/zipcoder/microlabs/mastering_loops/CarRideTest.java Voir le fichier

@@ -1,9 +0,0 @@
1
-package io.zipcoder.microlabs.mastering_loops;
2
-
3
-
4
-import org.junit.Test;
5
-
6
-public class CarRideTest {
7
-
8
-
9
-}

+ 112
- 0
src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java Voir le fichier

@@ -0,0 +1,112 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class NumberUtilitiesTest {
7
+    @Test
8
+    public void testGetRange1() {
9
+        // : Given
10
+        String expected = "51015";
11
+        int start = 5;
12
+        int stop = 20;
13
+        int step = 5;
14
+
15
+        // : When
16
+        String actual = NumberUtilities.getRange(start, stop, step);
17
+
18
+        // : Then
19
+        Assert.assertEquals(expected, actual);
20
+    }
21
+
22
+
23
+    @Test
24
+    public void testGetRange2() {
25
+        // : Given
26
+        String expected = "012345678910111213141516171819";
27
+        int start = 0;
28
+        int stop = 20;
29
+        int step = 1;
30
+
31
+        // : When
32
+        String actual = NumberUtilities.getRange(start, stop, step);
33
+
34
+        // : Then
35
+        Assert.assertEquals(expected, actual);
36
+    }
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+    @Test
52
+    public void testGetEvenNumbers() {
53
+        // : Given
54
+        String expected = "5791113151719";
55
+        int start = 5;
56
+        int stop = 20;
57
+
58
+        // : When
59
+        String actual = NumberUtilities.getEvenNumbers(start, stop);
60
+
61
+        // : Then
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void testGetOddNumbers() {
67
+        // : Given
68
+        String expected = "681012141618";
69
+        int start = 5;
70
+        int stop = 20;
71
+        int step = 5;
72
+
73
+        // : When
74
+        String actual = NumberUtilities.getOddNumbers(start, stop);
75
+
76
+        // : Then
77
+        Assert.assertEquals(expected, actual);
78
+    }
79
+
80
+
81
+
82
+    @Test
83
+    public void testGetSquareNumbers() {
84
+        // : Given
85
+        String expected = "25100225";
86
+        int start = 5;
87
+        int stop = 20;
88
+        int step = 5;
89
+
90
+        // : When
91
+        String actual = NumberUtilities.getSquareNumbers(start, stop, step);
92
+
93
+        // : Then
94
+        Assert.assertEquals(expected, actual);
95
+    }
96
+
97
+
98
+    @Test
99
+    public void testGetExponentiationNumbers() {
100
+        // : Given
101
+        String expected = "25100225";
102
+        int start = 5;
103
+        int stop = 20;
104
+        int step = 5;
105
+        int exponent = 2;
106
+
107
+        // : When
108
+        String actual = NumberUtilities.getExponentiations(start, stop, step, exponent);
109
+
110
+        Assert.assertEquals(expected, actual);
111
+    }
112
+}

+ 0
- 66
src/test/java/io/zipcoder/microlabs/mastering_loops/NumbersTest.java Voir le fichier

@@ -1,66 +0,0 @@
1
-package io.zipcoder.microlabs.mastering_loops;
2
-
3
-import org.junit.Assert;
4
-import org.junit.Test;
5
-
6
-public class NumbersTest {
7
-
8
-    @Test
9
-    public void oneToTenTest(){
10
-        //: Given
11
-        Numbers numbers = new Numbers();
12
-        String expected = "*** Output ***\noneToTen()\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
13
-
14
-        //: When
15
-        String actual = numbers.oneToTen();
16
-
17
-        //: Then
18
-        Assert.assertEquals("The two strings are equal", expected, actual);
19
-    }
20
-
21
-    @Test
22
-    public void oddNumbersTest(){
23
-        //: Given
24
-
25
-        //: When
26
-
27
-        //: Then
28
-    }
29
-
30
-    @Test
31
-    public void squaresTest(){
32
-        //: Given
33
-
34
-        //: When
35
-
36
-        //: Then
37
-    }
38
-
39
-    @Test
40
-    public void random4Test(){
41
-        //: Given
42
-
43
-        //: When
44
-
45
-        //: Then
46
-    }
47
-
48
-    @Test
49
-    public void evenTest(){
50
-        //: Given
51
-
52
-        //: When
53
-
54
-        //: Then
55
-    }
56
-
57
-    @Test
58
-    public void powersTest(){
59
-        //: Given
60
-
61
-        //: When
62
-
63
-        //: Then
64
-    }
65
-
66
-}

+ 0
- 28
src/test/java/io/zipcoder/microlabs/mastering_loops/ShapesTest.java Voir le fichier

@@ -1,28 +0,0 @@
1
-package io.zipcoder.microlabs.mastering_loops;
2
-
3
-
4
-import org.junit.Test;
5
-import org.junit.Assert;
6
-
7
-public class ShapesTest {
8
-
9
-
10
-
11
-    @Test
12
-    public void triangleTest(){
13
-        //: Given
14
-
15
-        //: When
16
-
17
-        //: Then
18
-    }
19
-
20
-    @Test
21
-    public void tableSquareTest(){
22
-        //: Given
23
-
24
-        //: When
25
-
26
-        //: Then
27
-    }
28
-}

+ 70
- 0
src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java Voir le fichier

@@ -0,0 +1,70 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 1/31/18.
8
+ */
9
+public class TableUtilitiesTest {
10
+    @Test
11
+    public void testGetLargeMultiplicationTable() {
12
+        String expected =
13
+                "  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 |\n" +
14
+                "  2 |  4 |  6 |  8 | 10 | 12 | 14 | 16 | 18 | 20 |\n" +
15
+                "  3 |  6 |  9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |\n" +
16
+                "  4 |  8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |\n" +
17
+                "  5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |\n" +
18
+                "  6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |\n" +
19
+                "  7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |\n" +
20
+                "  8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |\n" +
21
+                "  9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |\n" +
22
+                " 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |\n";
23
+
24
+        String actual = TableUtilities.getLargeMultiplicationTable();
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+
28
+
29
+    @Test
30
+    public void testGetSmallMultiplicationTable() {
31
+        String expected =
32
+                        "  1 |  2 |  3 |  4 |  5 |\n" +
33
+                        "  2 |  4 |  6 |  8 | 10 |\n" +
34
+                        "  3 |  6 |  9 | 12 | 15 |\n" +
35
+                        "  4 |  8 | 12 | 16 | 20 |\n" +
36
+                        "  5 | 10 | 15 | 20 | 25 |\n";
37
+
38
+        String actual = TableUtilities.getSmallMultiplicationTable();
39
+        Assert.assertEquals(expected, actual);
40
+    }
41
+
42
+    @Test
43
+    public void testGetMultiplicationTable() {
44
+        String expected =
45
+                "  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |\n" +
46
+                "  2 |  4 |  6 |  8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 |\n" +
47
+                "  3 |  6 |  9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 45 | 48 | 51 | 54 | 57 | 60 |\n" +
48
+                "  4 |  8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 |\n" +
49
+                "  5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 |100 |\n" +
50
+                "  6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 | 66 | 72 | 78 | 84 | 90 | 96 |102 |108 |114 |120 |\n" +
51
+                "  7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 | 77 | 84 | 91 | 98 |105 |112 |119 |126 |133 |140 |\n" +
52
+                "  8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 | 88 | 96 |104 |112 |120 |128 |136 |144 |152 |160 |\n" +
53
+                "  9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 | 99 |108 |117 |126 |135 |144 |153 |162 |171 |180 |\n" +
54
+                " 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |110 |120 |130 |140 |150 |160 |170 |180 |190 |200 |\n" +
55
+                " 11 | 22 | 33 | 44 | 55 | 66 | 77 | 88 | 99 |110 |121 |132 |143 |154 |165 |176 |187 |198 |209 |220 |\n" +
56
+                " 12 | 24 | 36 | 48 | 60 | 72 | 84 | 96 |108 |120 |132 |144 |156 |168 |180 |192 |204 |216 |228 |240 |\n" +
57
+                " 13 | 26 | 39 | 52 | 65 | 78 | 91 |104 |117 |130 |143 |156 |169 |182 |195 |208 |221 |234 |247 |260 |\n" +
58
+                " 14 | 28 | 42 | 56 | 70 | 84 | 98 |112 |126 |140 |154 |168 |182 |196 |210 |224 |238 |252 |266 |280 |\n" +
59
+                " 15 | 30 | 45 | 60 | 75 | 90 |105 |120 |135 |150 |165 |180 |195 |210 |225 |240 |255 |270 |285 |300 |\n" +
60
+                " 16 | 32 | 48 | 64 | 80 | 96 |112 |128 |144 |160 |176 |192 |208 |224 |240 |256 |272 |288 |304 |320 |\n" +
61
+                " 17 | 34 | 51 | 68 | 85 |102 |119 |136 |153 |170 |187 |204 |221 |238 |255 |272 |289 |306 |323 |340 |\n" +
62
+                " 18 | 36 | 54 | 72 | 90 |108 |126 |144 |162 |180 |198 |216 |234 |252 |270 |288 |306 |324 |342 |360 |\n" +
63
+                " 19 | 38 | 57 | 76 | 95 |114 |133 |152 |171 |190 |209 |228 |247 |266 |285 |304 |323 |342 |361 |380 |\n" +
64
+                " 20 | 40 | 60 | 80 |100 |120 |140 |160 |180 |200 |220 |240 |260 |280 |300 |320 |340 |360 |380 |400 |\n";
65
+
66
+        String actual = TableUtilities.getMultiplicationTable(20);
67
+        Assert.assertEquals(expected, actual);
68
+    }
69
+
70
+}

+ 72
- 0
src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java Voir le fichier

@@ -0,0 +1,72 @@
1
+package io.zipcoder.microlabs.mastering_loops;
2
+
3
+
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+public class TriangleUtilitiesTest {
8
+
9
+    @Test
10
+    public void getRow() {
11
+        String expected = "********************";
12
+        int width = 20;
13
+        String actual = TriangleUtilities.getRow(width);
14
+        Assert.assertEquals(expected, actual);
15
+    }
16
+
17
+
18
+    @Test
19
+    public void getTriangleTest1() {
20
+        String expected =
21
+                "*\n" +
22
+                        "**\n" +
23
+                        "***\n" +
24
+                        "****\n" +
25
+                        "*****\n" +
26
+                        "******\n" +
27
+                        "*******\n" +
28
+                        "********\n" +
29
+                        "*********\n";
30
+        String actual = TriangleUtilities.getTriangle(10);
31
+        Assert.assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void getTriangleTest2() {
36
+        String expected =
37
+                "*\n" +
38
+                        "**\n" +
39
+                        "***\n" +
40
+                        "****\n";
41
+        String actual = TriangleUtilities.getTriangle(5);
42
+        Assert.assertEquals(expected, actual);
43
+    }
44
+
45
+    @Test
46
+    public void testGetLargeTriangle() {
47
+        String expected =
48
+                "*\n" +
49
+                "**\n" +
50
+                "***\n" +
51
+                "****\n" +
52
+                "*****\n" +
53
+                "******\n" +
54
+                "*******\n" +
55
+                "********\n" +
56
+                "*********\n";
57
+        String actual = TriangleUtilities.getLargeTriangle();
58
+        Assert.assertEquals(expected, actual);
59
+    }
60
+
61
+
62
+    @Test
63
+    public void testGetSmallTriangle() {
64
+        String expected =
65
+                        "*\n" +
66
+                        "**\n" +
67
+                        "***\n" +
68
+                        "****\n";
69
+        String actual = TriangleUtilities.getSmallTriangle();
70
+        Assert.assertEquals(expected, actual);
71
+    }
72
+}

BIN
target/classes/io/zipcoder/microlabs/mastering_loops/MainApp.class Voir le fichier


BIN
target/classes/io/zipcoder/microlabs/mastering_loops/NumberUtilities.class Voir le fichier


BIN
target/classes/io/zipcoder/microlabs/mastering_loops/TableUtilities.class Voir le fichier


BIN
target/classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.class Voir le fichier


BIN
target/test-classes/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.class Voir le fichier


BIN
target/test-classes/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.class Voir le fichier


BIN
target/test-classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.class Voir le fichier