Jamez-s vor 6 Jahren
Ursprung
Commit
c2b0959e98
4 geänderte Dateien mit 43 neuen und 18 gelöschten Zeilen
  1. 13
    3
      TableUtilities.java
  2. 19
    4
      TriangleUtilities.java
  3. 1
    1
      TriangleUtilitiesTest.java
  4. 10
    10
      package.bluej

+ 13
- 3
TableUtilities.java Datei anzeigen

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

+ 19
- 4
TriangleUtilities.java Datei anzeigen

@@ -3,19 +3,34 @@
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+        String row = "";
7
+        
8
+        for(int i=0; i<numberOfStars; i++) {
9
+            row = row + "*"; //row+="*"
10
+        }
11
+        return row;
7 12
     }
8 13
     
9 14
     public static String getTriangle(int numberOfRows) {
10
-        return null;
15
+        String triangle = "";
16
+        
17
+        for (int i=0; i<numberOfRows; i++) {
18
+            if (numberOfRows == 1) { // special case
19
+                return "*";
20
+            }
21
+            
22
+            triangle = triangle + getRow(i+1);
23
+            triangle = triangle + "\n";
24
+        }
25
+        return triangle;
11 26
     }
12 27
 
13 28
 
14 29
     public static String getSmallTriangle() {
15
-        return null;
30
+        return getTriangle(4);
16 31
     }
17 32
 
18 33
     public static String getLargeTriangle() {
19
-        return null;
34
+        return getTriangle(9);
20 35
     }
21 36
 }

+ 1
- 1
TriangleUtilitiesTest.java Datei anzeigen

@@ -35,7 +35,7 @@ public class TriangleUtilitiesTest {
35 35
     @Test
36 36
     public void testGetTriangle_ForOneRow() {
37 37
         // Given
38
-        String expected = "*\n";
38
+        String expected = "*";
39 39
 
40 40
         // When
41 41
         String actual = TriangleUtilities.getTriangle(1);

+ 10
- 10
package.bluej Datei anzeigen

@@ -1,20 +1,20 @@
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
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 15
 objectbench.height=164
16
-objectbench.width=484
17
-package.divider.horizontal=0.6
16
+objectbench.width=286
17
+package.divider.horizontal=0.6004098360655737
18 18
 package.divider.vertical=0.7560627674750356
19 19
 package.editor.height=523
20 20
 package.editor.width=382