#35 Numbers Tables and Triangles

Offen
akeemcherry möchte 1 Commits von akeemcherry/CR-MicroLabs-Loops-NumbersTrianglesTables:master nach master zusammenführen
4 geänderte Dateien mit 109 neuen und 30 gelöschten Zeilen
  1. 46
    14
      NumberUtilities.java
  2. 24
    3
      TableUtilities.java
  3. 30
    4
      TriangleUtilities.java
  4. 9
    9
      package.bluej

+ 46
- 14
NumberUtilities.java Datei anzeigen

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

+ 24
- 3
TableUtilities.java Datei anzeigen

@@ -2,14 +2,35 @@
2 2
 
3 3
 public class TableUtilities {
4 4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+        String result = "";
6
+        for (int i=1;i<=5;i++){
7
+            for (int j=1;j<=5;j++){
8
+                result+= String.format(" %2d |",j*i);
9
+            }
10
+            result+="\n";
11
+        }
12
+        return result;
6 13
     }
7 14
 
8 15
     public static String getLargeMultiplicationTable() {
9
-        return null;
16
+        String result = "";
17
+        for (int i=1;i<=10;i++){
18
+            for (int j=1;j<=10;j++){
19
+                result+= String.format("%3d |",j*i);
20
+            }
21
+            result+="\n";
22
+        }
23
+        return result;
10 24
     }
11 25
 
12 26
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
27
+        String result = "";
28
+        for (int i=1;i<=tableSize;i++){
29
+            for (int j=1;j<=tableSize;j++){
30
+                result+= String.format("%3d |",j*i);
31
+            }
32
+            result+="\n";
33
+        }
34
+        return result;
14 35
     }
15 36
 }

+ 30
- 4
TriangleUtilities.java Datei anzeigen

@@ -3,19 +3,45 @@
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+        String result = "";
7
+        for (int i=1;i<=numberOfStars;i++){
8
+            result+="*" ;
9
+        }
10
+        return result;
7 11
     }
8 12
     
9 13
     public static String getTriangle(int numberOfRows) {
10
-        return null;
14
+        String result = "";
15
+        for (int i=1;i<=numberOfRows;i++){
16
+            for (int j=1;j<=i;j++){
17
+                result+= "*";
18
+            }
19
+            result+="\n" ;
20
+        }
21
+        return result;
11 22
     }
12 23
 
13 24
 
14 25
     public static String getSmallTriangle() {
15
-        return null;
26
+        String result = "";
27
+        for (int i=1;i<=4;i++){
28
+            
29
+            for (int j=1;j<=i;j++){
30
+                result += "*" ;
31
+            }
32
+            result += "\n";
33
+        }
34
+        return result;
16 35
     }
17 36
 
18 37
     public static String getLargeTriangle() {
19
-        return null;
38
+        String result = "";
39
+        for (int i=1;i<=9;i++){
40
+            for (int j=1;j<=i;j++){
41
+                result += "*";
42
+            }
43
+            result += "\n";
44
+        }
45
+        return result;
20 46
     }
21 47
 }

+ 9
- 9
package.bluej Datei anzeigen

@@ -8,19 +8,19 @@ dependency2.type=UsesDependency
8 8
 dependency3.from=TableUtilitiesTest
9 9
 dependency3.to=TableUtilities
10 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=153
16 16
 objectbench.width=484
17 17
 package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
18
+package.divider.vertical=0.7553516819571865
19
+package.editor.height=487
20 20
 package.editor.width=382
21 21
 package.editor.x=20
22
-package.editor.y=57
23
-package.frame.height=759
22
+package.editor.y=23
23
+package.frame.height=712
24 24
 package.frame.width=508
25 25
 package.numDependencies=3
26 26
 package.numTargets=6