Browse Source

I finished the assignment

De'Jon Johnson 6 years ago
parent
commit
48820a18f2
4 changed files with 103 additions and 27 deletions
  1. 42
    12
      NumberUtilities.java
  2. 25
    4
      TableUtilities.java
  3. 30
    5
      TriangleUtilities.java
  4. 6
    6
      package.bluej

+ 42
- 12
NumberUtilities.java View File

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

+ 25
- 4
TableUtilities.java View File

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

+ 30
- 5
TriangleUtilities.java View File

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

+ 6
- 6
package.bluej View File

@@ -1,17 +1,17 @@
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=320
14
+editor.fx.0.y=53
15 15
 objectbench.height=164
16 16
 objectbench.width=484
17 17
 package.divider.horizontal=0.6