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