Quellcode durchsuchen

Finished Person Details

Nathan Hall vor 6 Jahren
Ursprung
Commit
ebf36924ca
1 geänderte Dateien mit 37 neuen und 18 gelöschten Zeilen
  1. 37
    18
      src/main/java/com/zipcodewilmington/PersonHandler.java

+ 37
- 18
src/main/java/com/zipcodewilmington/PersonHandler.java Datei anzeigen

@@ -7,53 +7,72 @@ public class PersonHandler {
7 7
     private final Person[] personArray;
8 8
 
9 9
     public PersonHandler(Person[] personArray) {
10
+
10 11
         this.personArray = personArray;
11 12
     }
12 13
 
13 14
     public String whileLoop() {
14 15
         String result = "";
15 16
         // assume there is a `counter`
16
-        // while `counter` is less than length of array
17
-            // begin loop
17
+        int counter = 0;
18
+        StringBuilder builder = new StringBuilder();
18 19
 
19
-                // use `counter` to identify the `current Person` in the array
20
-                // get `string Representation` of `currentPerson`
21
-                // append `stringRepresentation` to `result` variable
22
-
23
-            // end loop
20
+        // while `counter` is less than length of array
21
+        // begin loop
22
+        while (counter < personArray.length) {
23
+            builder.append(personArray[counter]);
24
+            result = builder.toString();
25
+            counter++;
26
+        }
27
+
28
+        // use `counter` to identify the `current Person` in the array
29
+        // get `string Representation` of `currentPerson`
30
+        // append `stringRepresentation` to `result` variable
31
+
32
+        // end loop
24 33
         return result;
25 34
     }
26 35
 
27 36
 
28
-
29 37
     public String forLoop() {
30 38
         String result = "";
31 39
         // identify initial value
32 40
         // identify terminal condition
33 41
         // identify increment
34 42
 
43
+        StringBuilder builder = new StringBuilder();
44
+
45
+        for (int counter = 0; counter < personArray.length; counter++) {
46
+            builder.append(personArray[counter]);
47
+            result = builder.toString();
48
+        }
49
+
35 50
         // use the above clauses to declare for-loop signature
36
-            // begin loop
37
-                // use `counter` to identify the `current Person` in the array
38
-                // get `string Representation` of `currentPerson`
39
-                // append `stringRepresentation` to `result` variable
40
-            // end loop
51
+        // begin loop
52
+        // use `counter` to identify the `current Person` in the array
53
+        // get `string Representation` of `currentPerson`
54
+        // append `stringRepresentation` to `result` variable
55
+        // end loop
41 56
 
42 57
         return result;
43 58
     }
44 59
 
45 60
 
46
-
47 61
     public String forEachLoop() {
48 62
         String result = "";
63
+        StringBuilder builder = new StringBuilder();
49 64
         // identify array's type
50 65
         // identify array's variable-name
66
+        for (Person i : personArray) {
67
+            builder.append(i);
68
+            result = builder.toString();
69
+        }
51 70
 
52 71
         // use the above discoveries to declare for-each-loop signature
53
-            // begin loop
54
-                // get `string Representation` of `currentPerson`
55
-                // append `stringRepresentation` to `result` variable
56
-            // end loop
72
+        // begin loop
73
+        // get `string Representation` of `currentPerson`
74
+        // append `stringRepresentation` to `result` variable
75
+        // end loop
57 76
 
58 77
         return result;
59 78
     }