Procházet zdrojové kódy

Merge 77c3af3183abe6ff176bf0116e5a9e3a23200a1e into 6026e5f68429fdeebffb1a314db6451e44f108c4

jcampbell28 před 6 roky
rodič
revize
78cbb75243
No account linked to committer's email

+ 37
- 7
src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java Zobrazit soubor

@@ -3,18 +3,37 @@ package io.zipcoder.microlabs.mastering_loops;
3 3
 
4 4
 public class NumberUtilities {
5 5
     public static String getEvenNumbers(int start, int stop) {
6
-        return null;
6
+    StringBuilder evenString = new StringBuilder();
7
+        if (start % 2 == 0) {
8
+        for (int i = start; i < stop; i++){
9
+            evenString.append(i);
10
+        }
11
+    }
12
+        return evenString.toString();
7 13
     }
8 14
 
9 15
 
10 16
     public static String getOddNumbers(int start, int stop) {
11
-        return null;
17
+        StringBuilder oddString = new StringBuilder();
18
+        if (start % 2 == 1) {
19
+            for (int i = start; i < stop; i++){
20
+                oddString.append(i);
21
+            }
22
+        }
23
+        return oddString.toString();
12 24
     }
13 25
 
14 26
 
15 27
     public static String getSquareNumbers(int start, int stop, int step) {
16
-        return null;
17
-    }
28
+        StringBuilder squareString = new StringBuilder();
29
+
30
+            for (int i = start; i < stop; i++){
31
+                squareString.append(i*i);
32
+            }
33
+        return squareString.toString();
34
+        }
35
+
36
+
18 37
 
19 38
     public static String getRange(int start) {
20 39
         return null;
@@ -26,11 +45,22 @@ public class NumberUtilities {
26 45
 
27 46
 
28 47
     public static String getRange(int start, int stop, int step) {
29
-        return null;
30
-    }
48
+    StringBuilder range = new StringBuilder();
31 49
 
50
+            for (int i = start; i<stop; i++) {
51
+                range.append(i);
52
+            } return range.toString();
53
+    }
54
+// must add to.String to range bc you made a string builder
32 55
 
33 56
     public static String getExponentiations(int start, int stop, int step, int exponent) {
34
-        return null;
57
+
58
+        StringBuilder exponentString = new StringBuilder();
59
+
60
+        for (int i = start; i < stop-1; i += step){
61
+            exponentString.append(Math.pow(i,exponent));
62
+        }
63
+        return exponentString.toString();
64
+
35 65
     }
36 66
 }

+ 37
- 3
src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java Zobrazit soubor

@@ -2,14 +2,48 @@ package io.zipcoder.microlabs.mastering_loops;
2 2
 
3 3
 public class TableUtilities {
4 4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+
6
+        StringBuilder tableOne = new StringBuilder();
7
+
8
+        for (int a = 1; a <= 5; a++){
9
+            for (int b = 1; b <= 5; b++){
10
+                int product = a * b;
11
+                tableOne.append(String.format("%3d |", product));
12
+            }
13
+            tableOne.append("\n");
14
+
15
+        }
16
+        return tableOne.toString();
6 17
     }
7 18
 
19
+
8 20
     public static String getLargeMultiplicationTable() {
9
-        return null;
21
+
22
+        StringBuilder tableOne = new StringBuilder();
23
+
24
+        for (int a = 1; a <= 10; a++){
25
+            for (int b = 1; b <= 10; b++){
26
+                int product = a * b;
27
+                tableOne.append(String.format("%3d |", product));
28
+            }
29
+            tableOne.append("\n");
30
+
31
+        }
32
+        return tableOne.toString();
10 33
     }
11 34
 
12 35
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
36
+
37
+        StringBuilder tableOne = new StringBuilder();
38
+
39
+        for (int a = 1; a <= tableSize; a++){
40
+            for (int b = 1; b <= tableSize; b++){
41
+                int product = a * b;
42
+                tableOne.append(String.format("%3d |", product));
43
+            }
44
+            tableOne.append("\n");
45
+
46
+        }
47
+        return tableOne.toString();
14 48
     }
15 49
 }

+ 46
- 4
src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java Zobrazit soubor

@@ -3,18 +3,60 @@ package io.zipcoder.microlabs.mastering_loops;
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getTriangle(int numberOfRows) {
6
-        return null;
6
+        System.out.println("Get Triangle");
7
+        String resultString = "";
8
+        System.out.println(resultString);
9
+        for (int i = 1; i < numberOfRows; i++){
10
+
11
+            String rowofStars = "";
12
+            for (int j = 0; j < i; j++){
13
+                rowofStars = rowofStars + "*";
14
+
15
+            }
16
+            resultString = resultString + rowofStars + "\n";
17
+        }
18
+
19
+        return resultString;
7 20
     }
8 21
 
9 22
     public static String getRow(int numberOfStars) {
10
-        return null;
23
+        System.out.println("Get Row");
24
+        String resultString = "";
25
+       for (int i = 0; i < numberOfStars; i++){
26
+           resultString = resultString + "*";
27
+       }
28
+       return resultString;
11 29
     }
12 30
 
13 31
     public static String getSmallTriangle() {
14
-        return null;
32
+        System.out.println("Get Small Triangle");
33
+        String resultString = "";
34
+        System.out.println(resultString);
35
+        for (int i = 1; i < 5; i++){
36
+            String rowofStars = "";
37
+            for (int j = 0; j < i; j++){
38
+                rowofStars = rowofStars + "*";
39
+
40
+            }
41
+            resultString = resultString + rowofStars + "\n";
42
+        }
43
+
44
+        return resultString;
15 45
     }
16 46
 
17 47
     public static String getLargeTriangle() {
18
-        return null;
48
+        System.out.println("Get Large Triangle");
49
+        String resultString = "";
50
+        System.out.println(resultString);
51
+        for (int i = 1; i < 10; i++){
52
+            String rowofStars = "";
53
+            for (int j = 0; j < i; j++){
54
+                rowofStars = rowofStars + "*";
55
+
56
+            }
57
+            resultString = resultString + rowofStars + "\n";
58
+        }
59
+
60
+        return resultString;
19 61
     }
20 62
 }

+ 2
- 2
src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java Zobrazit soubor

@@ -173,7 +173,7 @@ public class NumberUtilitiesTest {
173 173
     @Test
174 174
     public void testGetEvenNumbers() {
175 175
         // : Given
176
-        String expected = "5791113151719";
176
+        String expected = "681012141618";
177 177
         int start = 5;
178 178
         int stop = 20;
179 179
 
@@ -187,7 +187,7 @@ public class NumberUtilitiesTest {
187 187
     @Test
188 188
     public void testGetOddNumbers() {
189 189
         // : Given
190
-        String expected = "681012141618";
190
+        String expected = "5791113151719";
191 191
         int start = 5;
192 192
         int stop = 20;
193 193
         int step = 5;