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

Added comments to triangleUtilities and tableUtilities

Trinh Tong 6 лет назад
Родитель
Сommit
13155c4cb9
3 измененных файлов: 46 добавлений и 20 удалений
  1. 12
    0
      TableUtilities.java
  2. 16
    2
      TriangleUtilities.java
  3. 18
    18
      package.bluej

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

@@ -9,6 +9,18 @@ public class TableUtilities {
9 9
         return getMultiplicationTable(10);
10 10
     }
11 11
 
12
+    /**
13
+     * The two above methods, small/large MultiplicationTable, call on the
14
+     * getMultiplicationTable to produce the desired result. 
15
+     * 
16
+     * Originally, the same code was used for each method, and the 
17
+     * "tableSize" parameter was just the req'd table size (ie. 5).
18
+     * 
19
+     * However, since each method returns the same format, calling on 
20
+     * getMultiplicationTable becomes more efficient and cuts down on 
21
+     * repeat code.
22
+     * 
23
+     */
12 24
     public static String getMultiplicationTable(int tableSize) {
13 25
         StringBuilder multiTable = new StringBuilder();
14 26
         // nested for loop

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

@@ -1,7 +1,13 @@
1
- import java.util.*;
2 1
 
3
-public class TriangleUtilities {
4 2
 
3
+
4
+import java.util.*;
5
+
6
+public class TriangleUtilities {
7
+    /**
8
+     * method getRow uses a for loop to create 1 row of stars with a given
9
+     * number of stars as the parameter (numberOfStars)
10
+     */
5 11
     public static String getRow(int numberOfStars) {
6 12
         // Use StringBuilder and a loop
7 13
         
@@ -14,6 +20,14 @@ public class TriangleUtilities {
14 20
         return stars.toString();
15 21
     }
16 22
     
23
+    /**
24
+     * method getTriangle uses a nested for loop to build the triangle of stars 
25
+     * with StringBuilder. 
26
+     * 
27
+     * Since getSmallTriangle and getLargeTriangle are essentially fixed sizes of 
28
+     * the star triangles, I call the getTriangle method with the parameter 
29
+     * "numberOfRows"
30
+     */ 
17 31
     public static String getTriangle(int numberOfRows) {
18 32
         StringBuilder stars = new StringBuilder();
19 33
         

+ 18
- 18
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 11
 editor.fx.0.height=722
12
-editor.fx.0.width=800
13
-editor.fx.0.x=537
12
+editor.fx.0.width=897
13
+editor.fx.0.x=471
14 14
 editor.fx.0.y=28
15
-objectbench.height=164
16
-objectbench.width=484
15
+objectbench.height=165
16
+objectbench.width=426
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
18
+package.divider.vertical=0.7546362339514978
19
+package.editor.height=522
20
+package.editor.width=324
21
+package.editor.x=62
22
+package.editor.y=86
23 23
 package.frame.height=759
24
-package.frame.width=508
24
+package.frame.width=450
25 25
 package.numDependencies=3
26 26
 package.numTargets=6
27 27
 package.showExtends=true
@@ -37,8 +37,8 @@ target1.name=TableUtilitiesTest
37 37
 target1.showInterface=false
38 38
 target1.type=UnitTestTargetJunit4
39 39
 target1.width=110
40
-target1.x=100
41
-target1.y=270
40
+target1.x=130
41
+target1.y=310
42 42
 target2.height=50
43 43
 target2.name=TriangleUtilitiesTest
44 44
 target2.showInterface=false
@@ -52,8 +52,8 @@ target3.name=TableUtilities
52 52
 target3.showInterface=false
53 53
 target3.type=ClassTarget
54 54
 target3.width=110
55
-target3.x=70
56
-target3.y=300
55
+target3.x=100
56
+target3.y=340
57 57
 target4.association=NumberUtilitiesTest
58 58
 target4.height=50
59 59
 target4.name=NumberUtilities