Просмотр исходного кода

Nick Satinover - All Tests Pass

Nicholas Satinover 6 лет назад
Родитель
Сommit
d321612b1e
5 измененных файлов: 152 добавлений и 40 удалений
  1. 44
    10
      NumberUtilities.java
  2. 39
    3
      TableUtilities.java
  3. 44
    6
      TriangleUtilities.java
  4. 2
    2
      TriangleUtilitiesTest.java
  5. 23
    19
      package.bluej

+ 44
- 10
NumberUtilities.java Просмотреть файл

@@ -1,32 +1,66 @@
1
- 
1
+import java.lang.*;
2 2
 
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 str = "";
8
+        for(int i = 0; i < stop; i++)
9
+        {
10
+            str = str.concat(Integer.toString(i));
11
+        }
12
+        return str;
8 13
     }
9 14
     
10 15
     public static String getRange(int start, int stop) {
11
-        return null;
16
+        String str = "";
17
+        for(int i = start; i < stop; i++)
18
+        {
19
+            str = str.concat(Integer.toString(i));
20
+        }
21
+        return str;
12 22
     }
13 23
 
14
-
15 24
     public static String getRange(int start, int stop, int step) {
16
-        return null;
25
+        String str = "";
26
+        for(int i = start; i < stop; i += step)
27
+        {
28
+            str = str.concat(Integer.toString(i));
29
+        }
30
+        return str;
17 31
     }
18 32
     
33
+    
19 34
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
35
+        int startEven = (start % 2 != 0) ? start + 1 : start;
36
+        String str = "";
37
+        for(int i = startEven; i < stop; i += 2)
38
+        {
39
+            str = str.concat(Integer.toString(i));
40
+        }
41
+        return str;
21 42
     }
22 43
 
23
-
24 44
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
45
+        int startOdd = (start % 2 == 0) ? start + 1 : start;
46
+        String str = "";
47
+        for(int i = startOdd; i < stop; i += 2)
48
+        {
49
+            str = str.concat(Integer.toString(i));
50
+        }
51
+        return str;
26 52
     }
27 53
 
28 54
 
29 55
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
56
+        String str = "";
57
+        double exponentD = exponent;
58
+        int tempInt;
59
+        for(double i = start; i <= stop; i++)
60
+        {
61
+            tempInt = (int)(Math.pow(i, exponentD));
62
+            str = str.concat(Integer.toString(tempInt));
63
+        }
64
+        return str;
31 65
     }
32 66
 }

+ 39
- 3
TableUtilities.java Просмотреть файл

@@ -2,14 +2,50 @@
2 2
 
3 3
 public class TableUtilities {
4 4
     public static String getSmallMultiplicationTable() {
5
-        return null;
5
+        String str = "", strA = "";
6
+        int multiply = 1;
7
+        for(int i = 0; i < 5; i++)
8
+        {
9
+            for(int x = 1; x < 6; x++)
10
+            {
11
+                strA = strA.concat(String.format("%3d |", (x * multiply) ));
12
+            }
13
+            str = str.concat(strA + "\n");
14
+            strA = "";
15
+            multiply++;
16
+        }
17
+        return str;
6 18
     }
7 19
 
8 20
     public static String getLargeMultiplicationTable() {
9
-        return null;
21
+        String str = "", strA = "";
22
+        int multiply = 1;
23
+        for(int i = 0; i < 10; i++)
24
+        {
25
+            for(int x = 1; x < 11; x++)
26
+            {
27
+                strA = strA.concat(String.format("%3d |", (x * multiply) ));
28
+            }
29
+            str = str.concat(strA + "\n");
30
+            strA = "";
31
+            multiply++;
32
+        }
33
+        return str;
10 34
     }
11 35
 
12 36
     public static String getMultiplicationTable(int tableSize) {
13
-        return null;
37
+        String str = "", strA = "";
38
+        int multiply = 1;
39
+        for(int i = 0; i < tableSize; i++)
40
+        {
41
+            for(int x = 1; x <= tableSize; x++)
42
+            {
43
+                strA = strA.concat(String.format("%3d |", (x * multiply) ));
44
+            }
45
+            str = str.concat(strA + "\n");
46
+            strA = "";
47
+            multiply++;
48
+        }
49
+        return str;
14 50
     }
15 51
 }

+ 44
- 6
TriangleUtilities.java Просмотреть файл

@@ -3,19 +3,57 @@
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+        String str = "";
7
+        for(int i = 0; i < numberOfStars; i++)
8
+        {
9
+            str = str.concat("*");
10
+        }
11
+        return str;
7 12
     }
8 13
     
9 14
     public static String getTriangle(int numberOfRows) {
10
-        return null;
15
+        String str = "", strA = "";
16
+        
17
+        for(int i = 0; i < numberOfRows; i++)
18
+        {
19
+            for(int x = 0; x <= i; x++)
20
+            {
21
+                strA = strA.concat("*");
22
+            }
23
+            str = str.concat(strA + "\n");
24
+            strA = "";
25
+        }
26
+        return str;
11 27
     }
12 28
 
13 29
 
14
-    public static String getSmallTriangle() {
15
-        return null;
30
+    public static String getSmallTriangle(int numberOfRows) {
31
+        String str = "", strA = "";
32
+        
33
+        for(int i = 0; i < numberOfRows; i++)
34
+        {
35
+            for(int x = 0; x <= i; x++)
36
+            {
37
+                strA = strA.concat("*");
38
+            }
39
+            str = str.concat(strA + "\n");
40
+            strA = "";
41
+        }
42
+        return str;
16 43
     }
17 44
 
18
-    public static String getLargeTriangle() {
19
-        return null;
45
+    public static String getLargeTriangle(int numberOfRows) {
46
+        String str = "", strA = "";
47
+        
48
+        for(int i = 0; i < numberOfRows; i++)
49
+        {
50
+            for(int x = 0; x <= i; x++)
51
+            {
52
+                strA = strA.concat("*");
53
+            }
54
+            str = str.concat(strA + "\n");
55
+            strA = "";
56
+        }
57
+        return str;
20 58
     }
21 59
 }

+ 2
- 2
TriangleUtilitiesTest.java Просмотреть файл

@@ -88,7 +88,7 @@ public class TriangleUtilitiesTest {
88 88
                 "*******\n" +
89 89
                 "********\n" +
90 90
                 "*********\n";
91
-        String actual = TriangleUtilities.getLargeTriangle();
91
+        String actual = TriangleUtilities.getLargeTriangle(9);
92 92
         Assert.assertEquals(expected, actual);
93 93
     }
94 94
 
@@ -100,7 +100,7 @@ public class TriangleUtilitiesTest {
100 100
                         "**\n" +
101 101
                         "***\n" +
102 102
                         "****\n";
103
-        String actual = TriangleUtilities.getSmallTriangle();
103
+        String actual = TriangleUtilities.getSmallTriangle(4);
104 104
         Assert.assertEquals(expected, actual);
105 105
     }
106 106
 }

+ 23
- 19
package.bluej Просмотреть файл

@@ -2,26 +2,30 @@
2 2
 dependency1.from=NumberUtilitiesTest
3 3
 dependency1.to=NumberUtilities
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=TriangleUtilitiesTest
6
-dependency2.to=TriangleUtilities
5
+dependency2.from=TableUtilitiesTest
6
+dependency2.to=TableUtilities
7 7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=TriangleUtilitiesTest
9
+dependency3.to=TriangleUtilities
10 10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=722
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
23
-package.frame.height=759
24
-package.frame.width=508
11
+editor.fx.0.height=1057
12
+editor.fx.0.width=1920
13
+editor.fx.0.x=-240
14
+editor.fx.0.y=-1057
15
+editor.fx.1.height=709
16
+editor.fx.1.width=800
17
+editor.fx.1.x=240
18
+editor.fx.1.y=23
19
+objectbench.height=163
20
+objectbench.width=813
21
+package.divider.horizontal=0.6507936507936508
22
+package.divider.vertical=0.738863287250384
23
+package.editor.height=474
24
+package.editor.width=1154
25
+package.editor.x=0
26
+package.editor.y=23
27
+package.frame.height=709
28
+package.frame.width=1280
25 29
 package.numDependencies=3
26 30
 package.numTargets=6
27 31
 package.showExtends=true
@@ -66,7 +70,7 @@ target5.height=50
66 70
 target5.name=NumberUtilitiesTest
67 71
 target5.showInterface=false
68 72
 target5.type=UnitTestTargetJunit4
69
-target5.width=120
73
+target5.width=150
70 74
 target5.x=110
71 75
 target5.y=40
72 76
 target6.association=TriangleUtilitiesTest