#38 Steffon Williams, LoopsNumbersTrainglesTables

Aperto
Stwillia94 vorrebbe unire 1 commit da Stwillia94/CR-MicroLabs-Loops-NumbersTrianglesTables:master a master
4 ha cambiato i file con 118 aggiunte e 32 eliminazioni
  1. 51
    14
      NumberUtilities.java
  2. 25
    4
      TableUtilities.java
  3. 32
    4
      TriangleUtilities.java
  4. 10
    10
      package.bluej

+ 51
- 14
NumberUtilities.java Vedi File

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

+ 25
- 4
TableUtilities.java Vedi File

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

+ 32
- 4
TriangleUtilities.java Vedi File

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

+ 10
- 10
package.bluej Vedi File

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=-145
14
+editor.fx.0.y=-1057
15
+objectbench.height=165
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.7546362339514978
19
+package.editor.height=522
20
 package.editor.width=382
20
 package.editor.width=382
21
-package.editor.x=20
21
+package.editor.x=17
22
 package.editor.y=57
22
 package.editor.y=57
23
 package.frame.height=759
23
 package.frame.height=759
24
 package.frame.width=508
24
 package.frame.width=508