donnaj 6 lat temu
rodzic
commit
4229423a5b
4 zmienionych plików z 44 dodań i 38 usunięć
  1. 15
    15
      NumberUtilities.java
  2. 16
    5
      TableUtilities.java
  3. 9
    14
      TriangleUtilities.java
  4. 4
    4
      package.bluej

+ 15
- 15
NumberUtilities.java Wyświetl plik

14
     }
14
     }
15
     
15
     
16
     public static String getRange(int start, int stop) {
16
     public static String getRange(int start, int stop) {
17
-        StringBuilder sb2 = new StringBuilder();
17
+        StringBuilder sb = new StringBuilder();
18
         for(int i = start; i < stop; i++) {
18
         for(int i = start; i < stop; i++) {
19
-            sb2.append(i);
19
+            sb.append(i);
20
         }
20
         }
21
-        return sb2.toString();
21
+        return sb.toString();
22
     }
22
     }
23
 
23
 
24
 
24
 
25
     public static String getRange(int start, int stop, int step) {
25
     public static String getRange(int start, int stop, int step) {
26
-        StringBuilder sb3 = new StringBuilder();
26
+        StringBuilder sb = new StringBuilder();
27
         for(int i=start; i<stop; i+=step) {
27
         for(int i=start; i<stop; i+=step) {
28
-            sb3.append(i);
28
+            sb.append(i);
29
         }
29
         }
30
-        return sb3.toString();
30
+        return sb.toString();
31
     }
31
     }
32
     
32
     
33
     public static String getEvenNumbers(int start, int stop) {
33
     public static String getEvenNumbers(int start, int stop) {
34
-        StringBuilder sb4 = new StringBuilder();
34
+        StringBuilder sb = new StringBuilder();
35
         for(int i = start; i < stop; i++) {
35
         for(int i = start; i < stop; i++) {
36
             if(i%2==0) {
36
             if(i%2==0) {
37
-            sb4.append(i);}
37
+            sb.append(i);}
38
     }
38
     }
39
-        return sb4.toString();
39
+        return sb.toString();
40
     }
40
     }
41
 
41
 
42
 
42
 
43
 
43
 
44
     public static String getOddNumbers(int start, int stop) {
44
     public static String getOddNumbers(int start, int stop) {
45
-        StringBuilder sb5 = new StringBuilder();
45
+        StringBuilder sb = new StringBuilder();
46
         for(int i = start; i < stop; i++) {
46
         for(int i = start; i < stop; i++) {
47
             if(i%2!=0) {
47
             if(i%2!=0) {
48
-            sb5.append(i);}
48
+            sb.append(i);}
49
     }
49
     }
50
-        return sb5.toString();
50
+        return sb.toString();
51
     }
51
     }
52
 
52
 
53
 
53
 
54
     public static String getExponentiations(int start, int stop, int exponent) {
54
     public static String getExponentiations(int start, int stop, int exponent) {
55
-        StringBuilder sb6 = new StringBuilder();
55
+        StringBuilder sb = new StringBuilder();
56
         int exp = exponent;
56
         int exp = exponent;
57
         int answer = 0;
57
         int answer = 0;
58
         for(int i=start; i<=stop; i++) {
58
         for(int i=start; i<=stop; i++) {
59
-            sb6.append((int)Math.pow(i,exp));
59
+            sb.append((int)Math.pow(i,exp));
60
         }
60
         }
61
-        return sb6.toString();
61
+        return sb.toString();
62
     }
62
     }
63
 }
63
 }

+ 16
- 5
TableUtilities.java Wyświetl plik

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

+ 9
- 14
TriangleUtilities.java Wyświetl plik

1
- 
2
 
1
 
3
 public class TriangleUtilities {
2
 public class TriangleUtilities {
4
-
5
     public static String getRow(int numberOfStars) {
3
     public static String getRow(int numberOfStars) {
6
         String star = "*";
4
         String star = "*";
7
         String output = "";
5
         String output = "";
8
         int n = numberOfStars;
6
         int n = numberOfStars;
9
         for(int i =1; i<=n; i++) {
7
         for(int i =1; i<=n; i++) {
10
-            output = String.format("%s", star);
8
+            output += String.format("%s", star);
11
         }
9
         }
12
         return output;
10
         return output;
13
     }
11
     }
14
-    
12
+
15
     public static String getTriangle(int numberOfRows) {
13
     public static String getTriangle(int numberOfRows) {
16
-        String star = "*";
17
-        String output = "";
18
-        int n = numberOfRows;
19
-        for(int i =1; i<=n; i++) {
20
-            output += String.format("%s", star);
14
+        StringBuilder sb = new StringBuilder();
15
+        for(int i =1; i<=numberOfRows; i++) {
16
+            sb.append(getRow(i) + "\n");
21
         }
17
         }
22
-        return output;
18
+        return sb.toString();
23
     }
19
     }
24
 
20
 
25
-
26
     public static String getSmallTriangle() {
21
     public static String getSmallTriangle() {
27
-        return null;
22
+        return getTriangle(4);
28
     }
23
     }
29
-
24
+    
30
     public static String getLargeTriangle() {
25
     public static String getLargeTriangle() {
31
-        return null;
26
+        return getTriangle(9);
32
     }
27
     }
33
 }
28
 }

+ 4
- 4
package.bluej Wyświetl plik

8
 dependency3.from=NumberUtilitiesTest
8
 dependency3.from=NumberUtilitiesTest
9
 dependency3.to=NumberUtilities
9
 dependency3.to=NumberUtilities
10
 dependency3.type=UsesDependency
10
 dependency3.type=UsesDependency
11
-editor.fx.0.height=709
12
-editor.fx.0.width=800
13
-editor.fx.0.x=475
14
-editor.fx.0.y=23
11
+editor.fx.0.height=0
12
+editor.fx.0.width=0
13
+editor.fx.0.x=0
14
+editor.fx.0.y=0
15
 objectbench.height=152
15
 objectbench.height=152
16
 objectbench.width=424
16
 objectbench.width=424
17
 package.divider.horizontal=0.6002785515320335
17
 package.divider.horizontal=0.6002785515320335