Parcourir la source

Finished project

Christian Sheridan il y a 6 ans
Parent
révision
25bf6fb7ba
4 fichiers modifiés avec 102 ajouts et 30 suppressions
  1. 50
    13
      NumberUtilities.java
  2. 27
    3
      TableUtilities.java
  3. 15
    4
      TriangleUtilities.java
  4. 10
    10
      package.bluej

+ 50
- 13
NumberUtilities.java Voir le fichier

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

+ 27
- 3
TableUtilities.java Voir le fichier

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

+ 15
- 4
TriangleUtilities.java Voir le fichier

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

+ 10
- 10
package.bluej Voir le fichier

@@ -1,25 +1,25 @@
1 1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TableUtilitiesTest
3
+dependency1.to=TableUtilities
4 4
 dependency1.type=UsesDependency
5 5
 dependency2.from=TriangleUtilitiesTest
6 6
 dependency2.to=TriangleUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=NumberUtilitiesTest
9
+dependency3.to=NumberUtilities
10 10
 dependency3.type=UsesDependency
11 11
 editor.fx.0.height=722
12 12
 editor.fx.0.width=800
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
13
+editor.fx.0.x=536
14
+editor.fx.0.y=26
15 15
 objectbench.height=164
16
-objectbench.width=484
17
-package.divider.horizontal=0.6
16
+objectbench.width=286
17
+package.divider.horizontal=0.6004098360655737
18 18
 package.divider.vertical=0.7560627674750356
19 19
 package.editor.height=523
20 20
 package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
21
+package.editor.x=100
22
+package.editor.y=31
23 23
 package.frame.height=759
24 24
 package.frame.width=508
25 25
 package.numDependencies=3