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