瀏覽代碼

{Joson Loopy Lab}

Jacqueline Joson 6 年之前
父節點
當前提交
751f3e70ee
共有 4 個檔案被更改,包括 131 行新增37 行删除
  1. 41
    7
      NumberUtilities.java
  2. 35
    4
      TableUtilities.java
  3. 36
    7
      TriangleUtilities.java
  4. 19
    19
      package.bluej

+ 41
- 7
NumberUtilities.java 查看文件

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

+ 35
- 4
TableUtilities.java 查看文件

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

+ 36
- 7
TriangleUtilities.java 查看文件

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

+ 19
- 19
package.bluej 查看文件

@@ -1,27 +1,27 @@
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
-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
11
+editor.fx.0.height=712
12
+editor.fx.0.width=763
13
+editor.fx.0.x=519
14
+editor.fx.0.y=23
15
+objectbench.height=92
16
+objectbench.width=1256
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.8486238532110092
19
+package.editor.height=548
20
+package.editor.width=1154
21
+package.editor.x=86
22
+package.editor.y=23
23
+package.frame.height=712
24
+package.frame.width=1280
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true
@@ -45,7 +45,7 @@ target2.showInterface=false
45 45
 target2.type=UnitTestTargetJunit4
46 46
 target2.width=120
47 47
 target2.x=100
48
-target2.y=160
48
+target2.y=150
49 49
 target3.association=TableUtilitiesTest
50 50
 target3.height=50
51 51
 target3.name=TableUtilities
@@ -76,4 +76,4 @@ target6.showInterface=false
76 76
 target6.type=ClassTarget
77 77
 target6.width=120
78 78
 target6.x=70
79
-target6.y=190
79
+target6.y=180