#31 Lewis did this

Open
LewisDominguez wil 1 commits van LewisDominguez/CR-MicroLabs-Loops-NumbersTrianglesTables:master samenvoegen met master
5 gewijzigde bestanden met toevoegingen van 88 en 38 verwijderingen
  1. BIN
      .DS_Store
  2. 55
    14
      NumberUtilities.java
  3. 0
    0
      README.TXT
  4. 15
    6
      TriangleUtilities.java
  5. 18
    18
      package.bluej

BIN
.DS_Store Bestand weergeven


+ 55
- 14
NumberUtilities.java Bestand weergeven

1
- 
2
-
3
 
1
 
4
 public class NumberUtilities {
2
 public class NumberUtilities {
5
-    
6
     public static String getRange(int start) {
3
     public static String getRange(int start) {
7
-        return null;
4
+        StringBuilder range = new StringBuilder();
5
+        for (int i = 0; i < start; i++) {
6
+            range.append(i);
7
+        }
8
+
9
+        return range.toString();
10
+
8
     }
11
     }
9
-    
12
+
10
     public static String getRange(int start, int stop) {
13
     public static String getRange(int start, int stop) {
11
-        return null;
12
-    }
14
+        StringBuilder range = new StringBuilder();
15
+        for (int i = start; i < stop; i++) {
16
+            range.append(i);
17
+        }
13
 
18
 
19
+        return range.toString();
20
+    }
14
 
21
 
15
     public static String getRange(int start, int stop, int step) {
22
     public static String getRange(int start, int stop, int step) {
16
-        return null;
23
+        StringBuilder range = new StringBuilder();
24
+        for (int i = start; i < stop; i += step) {
25
+            range.append(i);
26
+        }
27
+
28
+        return range.toString();
17
     }
29
     }
18
-    
30
+
19
     public static String getEvenNumbers(int start, int stop) {
31
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
21
-    }
32
+        StringBuilder range = new StringBuilder();
33
+        if (start % 2 == 0) {
34
+            for (int i = start; i < stop; i += 2) {
35
+                range.append(i);
36
+            }
37
+        } else {
38
+            for (int i = start + 1; i < stop; i +=2) {
39
+                range.append(i);
40
+            }
41
+        }
22
 
42
 
43
+        
44
+        return range.toString();
45
+    }
23
 
46
 
24
     public static String getOddNumbers(int start, int stop) {
47
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
26
-    }
48
+        StringBuilder range = new StringBuilder();
49
+        if (start % 2 != 0) {
50
+            for (int i = start; i < stop; i += 2) {
51
+                range.append(i);
52
+            }
53
+        } else {
54
+            for (int i = start + 1; i < stop; i +=2) {
55
+                range.append(i);
56
+            }
57
+        }
27
 
58
 
59
+        
60
+        return range.toString();
61
+        
62
+    }
28
 
63
 
29
     public static String getExponentiations(int start, int stop, int exponent) {
64
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
65
+        StringBuilder range = new StringBuilder();
66
+        for (int i = start; i <= stop; i++) {
67
+            Math.pow(start, exponent);
68
+            range.append(i);
69
+        }
70
+
71
+        return range.toString();
31
     }
72
     }
32
 }
73
 }

+ 0
- 0
README.TXT Bestand weergeven


+ 15
- 6
TriangleUtilities.java Bestand weergeven

1
- 
2
 
1
 
3
 public class TriangleUtilities {
2
 public class TriangleUtilities {
4
-
5
     public static String getRow(int numberOfStars) {
3
     public static String getRow(int numberOfStars) {
6
-        return null;
4
+        StringBuilder row = new StringBuilder();
5
+        String star = "*";
6
+        for (int i = 0; i < numberOfStars; i++) {
7
+            row.append(star);
8
+
9
+        }
10
+        return row.toString();
7
     }
11
     }
8
-    
12
+
9
     public static String getTriangle(int numberOfRows) {
13
     public static String getTriangle(int numberOfRows) {
10
-        return null;
14
+        StringBuilder row = new StringBuilder();
15
+        String star = "*\n";
16
+        for (int i = 0; i < numberOfRows; i++) {
17
+            row.append(star);
18
+        }
19
+        return row.toString();
11
     }
20
     }
12
 
21
 
13
-
14
     public static String getSmallTriangle() {
22
     public static String getSmallTriangle() {
15
         return null;
23
         return null;
24
+
16
     }
25
     }
17
 
26
 
18
     public static String getLargeTriangle() {
27
     public static String getLargeTriangle() {

+ 18
- 18
package.bluej Bestand weergeven

1
 #BlueJ package file
1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TableUtilitiesTest
3
+dependency1.to=TableUtilities
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
 dependency2.from=TriangleUtilitiesTest
5
 dependency2.from=TriangleUtilitiesTest
6
 dependency2.to=TriangleUtilities
6
 dependency2.to=TriangleUtilities
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=NumberUtilitiesTest
9
+dependency3.to=NumberUtilities
10
 dependency3.type=UsesDependency
10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
12
-editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
15
-objectbench.height=164
11
+editor.fx.0.height=0
12
+editor.fx.0.width=0
13
+editor.fx.0.x=0
14
+editor.fx.0.y=0
15
+objectbench.height=156
16
 objectbench.width=484
16
 objectbench.width=484
17
 package.divider.horizontal=0.6
17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
18
+package.divider.vertical=0.7552552552552553
19
+package.editor.height=496
20
 package.editor.width=382
20
 package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
21
+package.editor.x=30
22
+package.editor.y=23
23
+package.frame.height=724
24
 package.frame.width=508
24
 package.frame.width=508
25
 package.numDependencies=3
25
 package.numDependencies=3
26
 package.numTargets=6
26
 package.numTargets=6
43
 target2.name=TriangleUtilitiesTest
43
 target2.name=TriangleUtilitiesTest
44
 target2.showInterface=false
44
 target2.showInterface=false
45
 target2.type=UnitTestTargetJunit4
45
 target2.type=UnitTestTargetJunit4
46
-target2.width=120
46
+target2.width=130
47
 target2.x=100
47
 target2.x=100
48
 target2.y=160
48
 target2.y=160
49
 target3.association=TableUtilitiesTest
49
 target3.association=TableUtilitiesTest
59
 target4.name=NumberUtilities
59
 target4.name=NumberUtilities
60
 target4.showInterface=false
60
 target4.showInterface=false
61
 target4.type=ClassTarget
61
 target4.type=ClassTarget
62
-target4.width=120
62
+target4.width=130
63
 target4.x=80
63
 target4.x=80
64
 target4.y=70
64
 target4.y=70
65
 target5.height=50
65
 target5.height=50
66
 target5.name=NumberUtilitiesTest
66
 target5.name=NumberUtilitiesTest
67
 target5.showInterface=false
67
 target5.showInterface=false
68
 target5.type=UnitTestTargetJunit4
68
 target5.type=UnitTestTargetJunit4
69
-target5.width=120
69
+target5.width=130
70
 target5.x=110
70
 target5.x=110
71
 target5.y=40
71
 target5.y=40
72
 target6.association=TriangleUtilitiesTest
72
 target6.association=TriangleUtilitiesTest
74
 target6.name=TriangleUtilities
74
 target6.name=TriangleUtilities
75
 target6.showInterface=false
75
 target6.showInterface=false
76
 target6.type=ClassTarget
76
 target6.type=ClassTarget
77
-target6.width=120
77
+target6.width=130
78
 target6.x=70
78
 target6.x=70
79
 target6.y=190
79
 target6.y=190