Ver código fonte

passed tests

Jennifer Chao 6 anos atrás
pai
commit
26b674815c

+ 28
- 0
src/main/java/com/zipcodewilmington/PersonHandler.java Ver arquivo

12
 
12
 
13
     public String whileLoop() {
13
     public String whileLoop() {
14
         String result = "";
14
         String result = "";
15
+
15
         // assume there is a `counter`
16
         // assume there is a `counter`
16
         // while `counter` is less than length of array
17
         // while `counter` is less than length of array
17
             // begin loop
18
             // begin loop
21
                 // append `stringRepresentation` to `result` variable
22
                 // append `stringRepresentation` to `result` variable
22
 
23
 
23
             // end loop
24
             // end loop
25
+
26
+        int counter = 0;
27
+
28
+        while (counter < personArray.length) {
29
+            Person currentPerson = personArray[counter];
30
+            String stringRepresentation = currentPerson.toString();
31
+            result = result.concat(stringRepresentation);
32
+            counter++;
33
+        }
34
+
24
         return result;
35
         return result;
25
     }
36
     }
26
 
37
 
28
 
39
 
29
     public String forLoop() {
40
     public String forLoop() {
30
         String result = "";
41
         String result = "";
42
+
31
         // identify initial value
43
         // identify initial value
32
         // identify terminal condition
44
         // identify terminal condition
33
         // identify increment
45
         // identify increment
39
                 // append `stringRepresentation` to `result` variable
51
                 // append `stringRepresentation` to `result` variable
40
             // end loop
52
             // end loop
41
 
53
 
54
+        int initial;
55
+        int termCon = personArray.length;
56
+        int increment = 1;
57
+
58
+        for (initial = 0; initial < termCon; initial += increment) {
59
+            Person currentPerson = personArray[initial];
60
+            String stringRepresentation = currentPerson.toString();
61
+            result = result.concat(stringRepresentation);
62
+        }
63
+
42
         return result;
64
         return result;
43
     }
65
     }
44
 
66
 
46
 
68
 
47
     public String forEachLoop() {
69
     public String forEachLoop() {
48
         String result = "";
70
         String result = "";
71
+
49
         // identify array's type
72
         // identify array's type
50
         // identify array's variable-name
73
         // identify array's variable-name
51
 
74
 
55
                 // append `stringRepresentation` to `result` variable
78
                 // append `stringRepresentation` to `result` variable
56
             // end loop
79
             // end loop
57
 
80
 
81
+        for (Person currentPerson : personArray) {
82
+            String stringRepresentation = currentPerson.toString();
83
+            result = result.concat(stringRepresentation);
84
+        }
85
+
58
         return result;
86
         return result;
59
     }
87
     }
60
 
88