Aliza Lang 6 vuotta sitten
vanhempi
commit
b27f4f4035
4 muutettua tiedostoa jossa 110 lisäystä ja 46 poistoa
  1. 36
    17
      NumberUtilities.java
  2. 28
    5
      TableUtilities.java
  3. 31
    9
      TriangleUtilities.java
  4. 15
    15
      package.bluej

+ 36
- 17
NumberUtilities.java Näytä tiedosto

1
- 
2
-
3
-
4
 public class NumberUtilities {
1
 public class NumberUtilities {
5
-    
6
-    public static String getRange(int start) {
7
-        return null;
2
+    public static String getRange(int stop) {
3
+        String str ="";
4
+        for (int i = 0; i < stop; i++){
5
+            str = str + i;
6
+        }
7
+        return str;
8
     }
8
     }
9
-    
9
+
10
     public static String getRange(int start, int stop) {
10
     public static String getRange(int start, int stop) {
11
-        return null;
11
+        String str ="";
12
+        for (int i = start; i < stop; i++){
13
+            str = str + i;
14
+        }
15
+        return str;
12
     }
16
     }
13
 
17
 
14
-
15
     public static String getRange(int start, int stop, int step) {
18
     public static String getRange(int start, int stop, int step) {
16
-        return null;
19
+        String str = "";
20
+        for (int i = start; i < stop; i=i+step){
21
+            str = str + i;
22
+        }
23
+        return str;
17
     }
24
     }
18
-    
25
+
19
     public static String getEvenNumbers(int start, int stop) {
26
     public static String getEvenNumbers(int start, int stop) {
20
-        return null;
27
+        String str = "";
28
+        for (int i = start; i < stop; i++)
29
+            if (i % 2 == 0) {
30
+                str = str +i;
31
+            }
32
+        return str;
21
     }
33
     }
22
 
34
 
23
-
24
     public static String getOddNumbers(int start, int stop) {
35
     public static String getOddNumbers(int start, int stop) {
25
-        return null;
36
+        String str = "";
37
+        for (int i = start; i < stop; i++)
38
+            if (i % 2 == 1){
39
+                str = str + i;
40
+            }
41
+        return str;
26
     }
42
     }
27
 
43
 
28
-
29
     public static String getExponentiations(int start, int stop, int exponent) {
44
     public static String getExponentiations(int start, int stop, int exponent) {
30
-        return null;
45
+        String str = "";
46
+        for (int i = start; i <= stop; i++){
47
+            str = str + (int) Math.pow(i, exponent);
48
+        }
49
+        return str; 
31
     }
50
     }
32
-}
51
+}

+ 28
- 5
TableUtilities.java Näytä tiedosto

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

+ 31
- 9
TriangleUtilities.java Näytä tiedosto

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

+ 15
- 15
package.bluej Näytä tiedosto

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
6
-dependency2.to=TriangleUtilities
5
+dependency2.from=NumberUtilitiesTest
6
+dependency2.to=NumberUtilities
7
 dependency2.type=UsesDependency
7
 dependency2.type=UsesDependency
8
-dependency3.from=TableUtilitiesTest
9
-dependency3.to=TableUtilities
8
+dependency3.from=TriangleUtilitiesTest
9
+dependency3.to=TriangleUtilities
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
13
-editor.fx.0.x=537
14
-editor.fx.0.y=28
12
+editor.fx.0.width=634
13
+editor.fx.0.x=806
14
+editor.fx.0.y=23
15
 objectbench.height=164
15
 objectbench.height=164
16
-objectbench.width=484
17
-package.divider.horizontal=0.6
16
+objectbench.width=401
17
+package.divider.horizontal=0.6465927099841522
18
 package.divider.vertical=0.7560627674750356
18
 package.divider.vertical=0.7560627674750356
19
 package.editor.height=523
19
 package.editor.height=523
20
-package.editor.width=382
21
-package.editor.x=20
22
-package.editor.y=57
20
+package.editor.width=525
21
+package.editor.x=789
22
+package.editor.y=23
23
 package.frame.height=759
23
 package.frame.height=759
24
-package.frame.width=508
24
+package.frame.width=651
25
 package.numDependencies=3
25
 package.numDependencies=3
26
 package.numTargets=6
26
 package.numTargets=6
27
 package.showExtends=true
27
 package.showExtends=true