瀏覽代碼

Merge 77c3af3183abe6ff176bf0116e5a9e3a23200a1e into 6026e5f68429fdeebffb1a314db6451e44f108c4

jcampbell28 6 年之前
父節點
當前提交
78cbb75243
沒有帳戶連結到提交者的電子郵件

+ 37
- 7
src/main/java/io/zipcoder/microlabs/mastering_loops/NumberUtilities.java 查看文件

3
 
3
 
4
 public class NumberUtilities {
4
 public class NumberUtilities {
5
     public static String getEvenNumbers(int start, int stop) {
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
     public static String getOddNumbers(int start, int stop) {
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
     public static String getSquareNumbers(int start, int stop, int step) {
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
     public static String getRange(int start) {
38
     public static String getRange(int start) {
20
         return null;
39
         return null;
26
 
45
 
27
 
46
 
28
     public static String getRange(int start, int stop, int step) {
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
     public static String getExponentiations(int start, int stop, int step, int exponent) {
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 查看文件

2
 
2
 
3
 public class TableUtilities {
3
 public class TableUtilities {
4
     public static String getSmallMultiplicationTable() {
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
     public static String getLargeMultiplicationTable() {
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
     public static String getMultiplicationTable(int tableSize) {
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 查看文件

3
 public class TriangleUtilities {
3
 public class TriangleUtilities {
4
 
4
 
5
     public static String getTriangle(int numberOfRows) {
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
     public static String getRow(int numberOfStars) {
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
     public static String getSmallTriangle() {
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
     public static String getLargeTriangle() {
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 查看文件

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