#28 My Loops

Abierta
JaseG256 desea fusionar 1 commits de JaseG256/CR-MicroLabs-Loops-NumbersTrianglesTables:master en master
Se han modificado 4 ficheros con 70 adiciones y 23 borrados
  1. 35
    7
      NumberUtilities.java
  2. 6
    0
      TableUtilities.java
  3. 17
    4
      TriangleUtilities.java
  4. 12
    12
      package.bluej

+ 35
- 7
NumberUtilities.java Ver fichero

3
 
3
 
4
 public class NumberUtilities {
4
 public class NumberUtilities {
5
     
5
     
6
-    public static String getRange(int start) {
7
-        return null;
6
+    public static String getRange(int stop) {
7
+        String range = "";
8
+        for (int i = 0; i < stop; i++) {
9
+         range += i;   
10
+        }
11
+        return range;
8
     }
12
     }
9
     
13
     
10
     public static String getRange(int start, int stop) {
14
     public static String getRange(int start, int stop) {
11
-        return null;
15
+        String range = "";
16
+        for (int i = start; i < stop; i++) {
17
+            range += i;
18
+        }
19
+        return range;
12
     }
20
     }
13
 
21
 
14
 
22
 
15
     public static String getRange(int start, int stop, int step) {
23
     public static String getRange(int start, int stop, int step) {
16
-        return null;
24
+        String range = "";
25
+        for (int i = start; i < stop; i += step) {
26
+            range += i;   
27
+        }
28
+        return range;
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;
32
+        String evenNumber = "";
33
+        for (int i = start; i < stop; i++) {
34
+            if (i % 2 == 0) {
35
+                evenNumber += i;
36
+            }
37
+        }
38
+        return evenNumber;
21
     }
39
     }
22
 
40
 
23
 
41
 
24
     public static String getOddNumbers(int start, int stop) {
42
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
43
+        String oddNumber = "";
44
+        for (int i = start; i < stop; i++) {
45
+            if (i % 2 != 0) {
46
+                oddNumber += i;
47
+            }
48
+        }
49
+        return oddNumber;
26
     }
50
     }
27
 
51
 
28
 
52
 
29
     public static String getExponentiations(int start, int stop, int exponent) {
53
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
54
+        String numberSquared = "";
55
+        for (int i = start; i < stop; i++) {
56
+            numberSquared += Math.pow(i, exponent);
57
+        }
58
+        return numberSquared;
31
     }
59
     }
32
 }
60
 }

+ 6
- 0
TableUtilities.java Ver fichero

2
 
2
 
3
 public class TableUtilities {
3
 public class TableUtilities {
4
     public static String getSmallMultiplicationTable() {
4
     public static String getSmallMultiplicationTable() {
5
+        StringBuilder timesTable = new StringBuilder();
6
+        for (int i = 0; i <= 4; i++) {
7
+         for (int j = 0; j < i; i++) {
8
+             
9
+            }
10
+        }
5
         return null;
11
         return null;
6
     }
12
     }
7
 
13
 

+ 17
- 4
TriangleUtilities.java Ver fichero

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

+ 12
- 12
package.bluej Ver fichero

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
11
 editor.fx.0.height=722
12
 editor.fx.0.width=800
12
 editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
15
-objectbench.height=164
13
+editor.fx.0.x=268
14
+editor.fx.0.y=29
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.7556221889055472
19
+package.editor.height=497
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=-6
22
+package.editor.y=54
23
+package.frame.height=725
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