Преглед изворни кода

Added comments to NumberUtilities for readability

Trinh Tong пре 6 година
родитељ
комит
c310f12f5c
2 измењених фајлова са 36 додато и 7 уклоњено
  1. 21
    4
      NumberUtilities.java
  2. 15
    3
      TriangleUtilities.java

+ 21
- 4
NumberUtilities.java Прегледај датотеку

@@ -2,7 +2,10 @@
2 2
         
3 3
         
4 4
 public class NumberUtilities {
5
-        
5
+    /**
6
+     * Takes in one parameter "stop" to create a string of numbers, starting
7
+     * from 0 to stop, not including stop.
8
+     */    
6 9
         
7 10
         public static String getRange(int stop) {
8 11
             String numberRange = "";
@@ -14,6 +17,9 @@ public class NumberUtilities {
14 17
         return numberRange;
15 18
     }
16 19
     
20
+    /**
21
+     * Takes 2 parameters to dictate the range of the string.
22
+     */
17 23
     public static String getRange(int start, int stop) {
18 24
         String numberRange = "";
19 25
         
@@ -24,7 +30,9 @@ public class NumberUtilities {
24 30
         return numberRange;
25 31
     }
26 32
 
27
-
33
+    /**
34
+     * Uses the iterator to step and create the numbers in the range.
35
+     */
28 36
     public static String getRange(int start, int stop, int step) {
29 37
         String numberRange = "";
30 38
         
@@ -35,6 +43,10 @@ public class NumberUtilities {
35 43
         return numberRange;
36 44
     }
37 45
     
46
+    /**
47
+     * Uses the modulus operator to check for even/odd numbers to add to the 
48
+     * numberRange string.
49
+     */
38 50
     public static String getEvenNumbers(int start, int stop) {
39 51
         String numberRange = "";
40 52
         
@@ -47,7 +59,9 @@ public class NumberUtilities {
47 59
         return numberRange;
48 60
     }
49 61
 
50
-
62
+    /**
63
+     * See "getEvenNumbers"
64
+     */
51 65
     public static String getOddNumbers(int start, int stop) {
52 66
         String numberRange = "";
53 67
         
@@ -60,7 +74,10 @@ public class NumberUtilities {
60 74
         return numberRange;
61 75
     }
62 76
 
63
-
77
+    /**
78
+     * Uses Math.pow to raise i to a specific power, then casts it to an int 
79
+     * so it can be passed into the string to be returned.
80
+     */
64 81
     public static String getExponentiations(int start, int stop, int exponent) {
65 82
         String numberRange = "";
66 83
         

+ 15
- 3
TriangleUtilities.java Прегледај датотеку

@@ -1,13 +1,25 @@
1
- 
1
+ import java.util.*;
2 2
 
3 3
 public class TriangleUtilities {
4 4
 
5 5
     public static String getRow(int numberOfStars) {
6
-        return null;
6
+        // Use StringBuilder and a loop
7
+        
8
+        StringBuilder stars = new StringBuilder();
9
+        
10
+        for (int i = 0; i < numberOfStars; i++) {
11
+            stars.append("*"); 
12
+        }
13
+        
14
+        String starTriangle = stars.toString();
15
+        
16
+        return starTriangle;
7 17
     }
8 18
     
9 19
     public static String getTriangle(int numberOfRows) {
10
-        return null;
20
+        // numberOfRows -1 for each row 
21
+        // for loop for # of rows, decreasing by 1
22
+        return 
11 23
     }
12 24
 
13 25