Просмотр исходного кода

Merge pull request #28 from Zipcoder/feat/leon

Feat/leon
Git-Leon 6 лет назад
Родитель
Сommit
3f6a0b5516
Аккаунт пользователя с таким Email не найден
25 измененных файлов: 1023 добавлений и 328 удалений
  1. 252
    0
      README-NumberUtilities.md
  2. 234
    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. 69
    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. Двоичные данные
      target/classes/io/zipcoder/microlabs/mastering_loops/MainApp.class
  20. Двоичные данные
      target/classes/io/zipcoder/microlabs/mastering_loops/NumberUtilities.class
  21. Двоичные данные
      target/classes/io/zipcoder/microlabs/mastering_loops/TableUtilities.class
  22. Двоичные данные
      target/classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.class
  23. Двоичные данные
      target/test-classes/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.class
  24. Двоичные данные
      target/test-classes/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.class
  25. Двоичные данные
      target/test-classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.class

+ 252
- 0
README-NumberUtilities.md Просмотреть файл

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

+ 234
- 0
README-TableUtilities.md Просмотреть файл

@@ -0,0 +1,234 @@
1
+# TableUtilities
2
+* Ensure each of the test cases in the class [TableUtilitiesTest]() successfully passes upon completion of each method stubs in the class [TableUtilities]().
3
+    * `String getLargeMultiplicationTable()`
4
+    * `String getSmallMultiplicationTable()`
5
+    * `String getMultiplicationTable(int width)`
6
+
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
+
39
+## `String getSmallMultiplicationTable()`
40
+* **Description**
41
+    * Generate a `String` representation of a multiplication table whose dimensions are `4` by `4`
42
+	
43
+### Example 1
44
+* Sample Script
45
+
46
+    ```
47
+    // : Given    
48
+    // : When
49
+    String outcome = TableUtilities.getSmallMultiplicationTable();
50
+    
51
+    // : Then
52
+    System.out.println(outcome);
53
+    ```
54
+
55
+
56
+
57
+* Sample Output
58
+
59
+    ```
60
+      1 |  2 |  3 |  4 |
61
+      2 |  4 |  6 |  8 |
62
+      3 |  6 |  9 | 12 |
63
+      4 |  8 | 12 | 16 |
64
+    ```
65
+
66
+
67
+
68
+
69
+
70
+
71
+
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
+    
105
+
106
+## `String getLargeMultiplicationTable()`
107
+* **Description**
108
+    * Given one integer, `width`, generate a `String` representation of a multiplication table whose dimensions are `width` by `width`
109
+
110
+	
111
+### Example
112
+* Sample Script
113
+
114
+    ```
115
+    // : Given
116
+    int n = 3;
117
+    
118
+    // : When
119
+    String outcome = Tables.getLargeMultiplicationTable();
120
+    
121
+    // : Then
122
+    System.out.println(outcome);
123
+    ```
124
+
125
+
126
+
127
+* Sample Output
128
+
129
+    ```
130
+    1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 |
131
+    2 |  4 |  6 |  8 | 10 | 12 | 14 | 16 | 18 | 20 |
132
+    3 |  6 |  9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 |
133
+    4 |  8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 |
134
+    5 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 |
135
+    6 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 |
136
+    7 | 14 | 21 | 28 | 35 | 42 | 49 | 56 | 63 | 70 |
137
+    8 | 16 | 24 | 32 | 40 | 48 | 56 | 64 | 72 | 80 |
138
+    9 | 18 | 27 | 36 | 45 | 54 | 63 | 72 | 81 | 90 |
139
+   10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |100 |
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
+    
174
+    
175
+    
176
+    
177
+    
178
+## `String getMultiplicationTable(int width)`
179
+* **Description**
180
+    * Given one integer, `width`, generate a `String` representation of a multiplication table whose dimensions are `width` by `width`
181
+
182
+	
183
+### Example 1
184
+* Sample Script
185
+
186
+    ```
187
+    // : Given
188
+    int n = 3;
189
+    
190
+    // : When
191
+    String outcome = Tables.getMultiplicationTable(n);
192
+    
193
+    // : Then
194
+    System.out.println(outcome);
195
+    ```
196
+
197
+
198
+
199
+* Sample Output
200
+
201
+    ```
202
+      1 |  2 |  3 |
203
+      2 |  4 |  6 |
204
+      3 |  6 |  9 |
205
+    ```
206
+
207
+
208
+
209
+### Example 2
210
+* Sample Script
211
+
212
+    ```
213
+    // : Given
214
+    int n = 6;
215
+    
216
+    // : When
217
+    String outcome = Tables.getMultiplicationTable(n);
218
+    
219
+    // : Then
220
+    System.out.println(outcome);
221
+    ```
222
+
223
+
224
+
225
+* Sample Output
226
+
227
+    ```
228
+     1 |  2 |  3 |  4 |  5 |  6 |
229
+     2 |  4 |  6 |  8 | 10 | 12 |
230
+     3 |  6 |  9 | 12 | 15 | 18 |
231
+     4 |  8 | 12 | 16 | 20 | 24 |
232
+     5 | 10 | 15 | 20 | 25 | 30 |
233
+     6 | 12 | 18 | 24 | 30 | 36 |
234
+    ```

+ 156
- 0
README-TriangleUtilities.md Просмотреть файл

@@ -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 Просмотреть файл

@@ -1,171 +1,25 @@
1 1
 # ZCW-MicroLabs-Loops
2
+* Read through each of the following `README` files and complete each of the asks.
3
+    * [README-NumberUtilities.md](./README-NumberUtilities.md)
4
+    * [README-TriangleUtilities.md](./README-NumberUtilities.md)
5
+    * [README-TableUtilities.md](./README-NumberUtilities.md)
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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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
-}

+ 69
- 0
src/test/java/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.java Просмотреть файл

@@ -0,0 +1,69 @@
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
+        String actual = TableUtilities.getMultiplicationTable(20);
66
+        Assert.assertEquals(expected, actual);
67
+    }
68
+
69
+}

+ 72
- 0
src/test/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.java Просмотреть файл

@@ -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
+}

Двоичные данные
target/classes/io/zipcoder/microlabs/mastering_loops/MainApp.class Просмотреть файл


Двоичные данные
target/classes/io/zipcoder/microlabs/mastering_loops/NumberUtilities.class Просмотреть файл


Двоичные данные
target/classes/io/zipcoder/microlabs/mastering_loops/TableUtilities.class Просмотреть файл


Двоичные данные
target/classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.class Просмотреть файл


Двоичные данные
target/test-classes/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.class Просмотреть файл


Двоичные данные
target/test-classes/io/zipcoder/microlabs/mastering_loops/TableUtilitiesTest.class Просмотреть файл


Двоичные данные
target/test-classes/io/zipcoder/microlabs/mastering_loops/TriangleUtilitiesTest.class Просмотреть файл