Quellcode durchsuchen

Completed the Lab

William Brown vor 6 Jahren
Ursprung
Commit
aeef5b92a5
5 geänderte Dateien mit 125 neuen und 36 gelöschten Zeilen
  1. 42
    7
      NumberUtilities.java
  2. 36
    5
      TableUtilities.java
  3. 0
    2
      TableUtilitiesTest.java
  4. 29
    4
      TriangleUtilities.java
  5. 18
    18
      package.bluej

+ 42
- 7
NumberUtilities.java Datei anzeigen

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

+ 36
- 5
TableUtilities.java Datei anzeigen

@@ -1,15 +1,46 @@
1
- 
2
-
3 1
 public class TableUtilities {
4 2
     public static String getSmallMultiplicationTable() {
5
-        return null;
3
+        //NESTED FOR LOOPS
4
+        
5
+        //return String.format(" %1$2d | %2$2d |", 5, 10);
6
+        int outputInt = 0;
7
+        String output = "";
8
+        for(int i = 1; i <= 5; i++){
9
+            for(int j = 1; j <= 5; j++){
10
+                outputInt = i * j;
11
+                //output = output + Integer.toString(outputInt) + "|";
12
+                output = String.format("%1$s%2$3d |", output, outputInt);
13
+            }
14
+            output = output + "\n";
15
+        }
16
+        return output;
6 17
     }
7 18
 
8 19
     public static String getLargeMultiplicationTable() {
9
-        return null;
20
+        int outputInt = 0;
21
+        String output = "";
22
+        for(int i = 1; i <= 10; i++){
23
+            for(int j = 1; j <= 10; j++){
24
+                outputInt = i * j;
25
+                //output = output + Integer.toString(outputInt) + "|";
26
+                output = String.format("%1$s%2$3d |", output, outputInt);
27
+            }
28
+            output = output + "\n";
29
+        }
30
+        return output;
10 31
     }
11 32
 
12 33
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
34
+        int outputInt = 0;
35
+        String output = "";
36
+        for(int i = 1; i <= tableSize; i++){
37
+            for(int j = 1; j <= tableSize; j++){
38
+                outputInt = i * j;
39
+                //output = output + Integer.toString(outputInt) + "|";
40
+                output = String.format("%1$s%2$3d |", output, outputInt);
41
+            }
42
+            output = output + "\n";
43
+        }
44
+        return output;
14 45
     }
15 46
 }

+ 0
- 2
TableUtilitiesTest.java Datei anzeigen

@@ -1,5 +1,3 @@
1
- 
2
-
3 1
 import org.junit.Assert;
4 2
 import org.junit.Test;
5 3
 

+ 29
- 4
TriangleUtilities.java Datei anzeigen

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

+ 18
- 18
package.bluej Datei anzeigen

@@ -1,27 +1,27 @@
1 1
 #BlueJ package file
2
-dependency1.from=NumberUtilitiesTest
3
-dependency1.to=NumberUtilities
2
+dependency1.from=TriangleUtilitiesTest
3
+dependency1.to=TriangleUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=TriangleUtilitiesTest
6
-dependency2.to=TriangleUtilities
5
+dependency2.from=NumberUtilitiesTest
6
+dependency2.to=NumberUtilities
7 7
 dependency2.type=UsesDependency
8 8
 dependency3.from=TableUtilitiesTest
9 9
 dependency3.to=TableUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
11
+editor.fx.0.height=711
12 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
13
+editor.fx.0.x=480
14
+editor.fx.0.y=23
15
+objectbench.height=153
16
+objectbench.width=454
17 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
23
-package.frame.height=759
24
-package.frame.width=508
18
+package.divider.vertical=0.7549770290964778
19
+package.editor.height=486
20
+package.editor.width=352
21
+package.editor.x=0
22
+package.editor.y=27
23
+package.frame.height=711
24
+package.frame.width=478
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true
@@ -44,7 +44,7 @@ target2.name=TriangleUtilitiesTest
44 44
 target2.showInterface=false
45 45
 target2.type=UnitTestTargetJunit4
46 46
 target2.width=120
47
-target2.x=100
47
+target2.x=110
48 48
 target2.y=160
49 49
 target3.association=TableUtilitiesTest
50 50
 target3.height=50
@@ -75,5 +75,5 @@ target6.name=TriangleUtilities
75 75
 target6.showInterface=false
76 76
 target6.type=ClassTarget
77 77
 target6.width=120
78
-target6.x=70
78
+target6.x=80
79 79
 target6.y=190