浏览代码

first commit almost done

Kthomas 6 年前
父节点
当前提交
51bf5718c9

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

@@ -3,34 +3,91 @@ 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
+        String numList = "";
7
+
8
+        for (int i = start; i < stop; i++) {
9
+
10
+            if (i % 2 == 0) {
11
+
12
+                numList = numList + i;
13
+            }
14
+        }
15
+
16
+
17
+        return numList;
7 18
     }
8 19
 
9 20
 
10 21
     public static String getOddNumbers(int start, int stop) {
11
-        return null;
22
+
23
+        String numList = "";
24
+
25
+        for (int i = start; i < stop; i++) {
26
+
27
+            if (i % 2 != 0) {
28
+
29
+                numList = numList + i;
30
+            }
31
+        }
32
+        return numList;
12 33
     }
13 34
 
14 35
 
15 36
     public static String getSquareNumbers(int start, int stop, int step) {
16
-        return null;
37
+
38
+        String numList = "";
39
+
40
+        for (int i = start; i < stop; i += step) {
41
+
42
+            int theLid = (int) Math.pow(i, 2);
43
+            numList += String.valueOf(theLid);
44
+
45
+        }
46
+
47
+        return numList;
17 48
     }
18 49
 
19
-    public static String getRange(int start) {
20
-        return null;
50
+
51
+    public static String getRange(int stop) {
52
+        String numList = "";
53
+
54
+        for (int i = 0; i < stop; i++)
55
+            numList += String.valueOf(i);
56
+
57
+        return numList;
21 58
     }
22 59
 
60
+
61
+
23 62
     public static String getRange(int start, int stop) {
24
-        return null;
63
+        String numList = "";
64
+
65
+        for (int i = start; i < stop; i++)
66
+            numList += String.valueOf(i);
67
+
68
+        return numList;
25 69
     }
26 70
 
27 71
 
28 72
     public static String getRange(int start, int stop, int step) {
29
-        return null;
73
+        String numList = "";
74
+
75
+        for (int i = start; i < stop; i+=step)
76
+            numList += String.valueOf(i);
77
+
78
+        return numList;
30 79
     }
31 80
 
32 81
 
33 82
     public static String getExponentiations(int start, int stop, int step, int exponent) {
34
-        return null;
83
+
84
+        String numList = "";
85
+
86
+        for (int i = start; i < stop; i += step) {
87
+
88
+            int theLid = (int) Math.pow(i, exponent);
89
+            numList += String.valueOf(theLid);
90
+        }
91
+        return numList;
35 92
     }
36 93
 }

+ 12
- 1
src/main/java/io/zipcoder/microlabs/mastering_loops/TableUtilities.java 查看文件

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

+ 44
- 4
src/main/java/io/zipcoder/microlabs/mastering_loops/TriangleUtilities.java 查看文件

@@ -3,18 +3,58 @@ 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
+
7
+            String newTriangle = "*\n";
8
+            String newLine= "*";
9
+            int counter = 1;
10
+
11
+            while(counter < numberOfRows - 1){
12
+                 newLine += "*";
13
+                 newTriangle += newLine + "\n";
14
+                 counter++;
15
+          }
16
+         return newTriangle;
7 17
     }
8 18
 
9 19
     public static String getRow(int numberOfStars) {
10
-        return null;
20
+
21
+            String star = "";
22
+            int counter = 1;
23
+
24
+            while(counter <= numberOfStars) {
25
+                star = star + "*";
26
+                counter++;
27
+        }
28
+        return star;
11 29
     }
12 30
 
13 31
     public static String getSmallTriangle() {
14
-        return null;
32
+
33
+        String newTriangle = "*\n";
34
+        String newLine = "*";
35
+        int counter = 1;
36
+
37
+        while(counter < 4){
38
+            newLine += "*";
39
+            newTriangle += newLine + "\n";
40
+            counter++;
41
+        }
42
+        return newTriangle;
15 43
     }
16 44
 
17 45
     public static String getLargeTriangle() {
18
-        return null;
46
+
47
+            String newTriangle = "*\n";
48
+            String newLine = "*";
49
+            int counter = 1;
50
+
51
+            while(counter < 9){
52
+                newLine += "*";
53
+                newTriangle += newLine + "\n";
54
+                counter++;
55
+        }
56
+        return newTriangle;
19 57
     }
20 58
 }
59
+
60
+// woo!

+ 4
- 4
src/test/java/io/zipcoder/microlabs/mastering_loops/NumberUtilitiesTest.java 查看文件

@@ -8,7 +8,7 @@ public class NumberUtilitiesTest {
8 8
     public void testGetRange1A() {
9 9
         // : Given
10 10
         String expected = "0123456789";
11
-        int stop = 11;
11
+        int stop = 10;
12 12
 
13 13
         // : When
14 14
         String actual = NumberUtilities.getRange(stop);
@@ -87,7 +87,7 @@ public class NumberUtilitiesTest {
87 87
     @Test
88 88
     public void testGetRange3B() {
89 89
         // : Given
90
-        String expected = "100101103104105106107108109";
90
+        String expected = "100101102103104105106107108109";
91 91
         int start = 100;
92 92
         int stop = 110;
93 93
 
@@ -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;