#2 TG finished

Ouvert
tennesseegibbs veut fusionner 1 révision(s) depuis tennesseegibbs/CR-MicroLabs-Loops-NumbersTrianglesTables1:master vers master
4 fichiers modifiés avec 90 ajouts et 42 suppressions
  1. 42
    15
      NumberUtilities.java
  2. 13
    3
      TableUtilities.java
  3. 18
    7
      TriangleUtilities.java
  4. 17
    17
      package.bluej

+ 42
- 15
NumberUtilities.java Voir le fichier

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

+ 13
- 3
TableUtilities.java Voir le fichier

2
 
2
 
3
 public class TableUtilities {
3
 public class TableUtilities {
4
     public static String getSmallMultiplicationTable() {
4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+        return getMultiplicationTable(5);
6
     }
6
     }
7
 
7
 
8
     public static String getLargeMultiplicationTable() {
8
     public static String getLargeMultiplicationTable() {
9
-        return null;
9
+        return getMultiplicationTable(10);
10
     }
10
     }
11
 
11
 
12
     public static String getMultiplicationTable(int tableSize) {
12
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
13
+       StringBuilder builder = new StringBuilder();
14
+        for (int i = 1 ; i<= tableSize; i++) {
15
+            for (int t = 1 ; t <= tableSize; t++) {
16
+            builder.append(String.format("%3d |", (i*t)));
17
+            
18
+            }
19
+            builder.append("\n");
20
+            
21
+        
22
+        } return builder.toString();
14
     }
23
     }
15
 }
24
 }
25
+

+ 18
- 7
TriangleUtilities.java Voir le fichier

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 builder = new StringBuilder();
5
+        for (int i = 1 ; i<= numberOfStars; i++){
6
+            builder.append('*');
7
+
8
+        }
9
+        return builder.toString();
10
+
7
     }
11
     }
8
-    
12
+
9
     public static String getTriangle(int numberOfRows) {
13
     public static String getTriangle(int numberOfRows) {
10
-        return null;
14
+        StringBuilder builder = new StringBuilder();
15
+        for (int i = 1 ; i <= numberOfRows; i++){
16
+            String triangle = getRow(i);
17
+            builder.append(triangle + "\n");  
18
+
19
+        }
20
+        return builder.toString();
21
+
11
     }
22
     }
12
 
23
 
13
 
24
 
14
     public static String getSmallTriangle() {
25
     public static String getSmallTriangle() {
15
-        return null;
26
+        return getTriangle(4);
16
     }
27
     }
17
 
28
 
18
     public static String getLargeTriangle() {
29
     public static String getLargeTriangle() {
19
-        return null;
30
+        return getTriangle(9);
20
     }
31
     }
21
 }
32
 }

+ 17
- 17
package.bluej Voir le fichier

1
 #BlueJ package file
1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TriangleUtilitiesTest
3
+dependency1.to=TriangleUtilities
4
 dependency1.type=UsesDependency
4
 dependency1.type=UsesDependency
5
-dependency2.from=TriangleUtilitiesTest
6
-dependency2.to=TriangleUtilities
5
+dependency2.from=TableUtilitiesTest
6
+dependency2.to=TableUtilities
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
16
-objectbench.width=484
17
-package.divider.horizontal=0.6
18
-package.divider.vertical=0.7560627674750356
19
-package.editor.height=523
20
-package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
13
+editor.fx.0.x=-192
14
+editor.fx.0.y=-722
15
+objectbench.height=98
16
+objectbench.width=387
17
+package.divider.horizontal=0.5996955859969558
18
+package.divider.vertical=0.8502139800285307
19
+package.editor.height=589
20
+package.editor.width=551
21
+package.editor.x=-181
22
+package.editor.y=-1001
23
 package.frame.height=759
23
 package.frame.height=759
24
-package.frame.width=508
24
+package.frame.width=677
25
 package.numDependencies=3
25
 package.numDependencies=3
26
 package.numTargets=6
26
 package.numTargets=6
27
 package.showExtends=true
27
 package.showExtends=true