-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPersonHandler.java
More file actions
88 lines (67 loc) · 2.42 KB
/
PersonHandler.java
File metadata and controls
88 lines (67 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.zipcodewilmington;
/**
* Created by leon on 1/24/18.
*/
public class PersonHandler {
private final Person[] personArray;
public PersonHandler(Person[] personArray) {
this.personArray = personArray;
}
public String whileLoop() {
String result = "";
int count = 0;
while (count < personArray.length) {
for (int i = 0; i < personArray.length; i++) {
result += personArray[count].toString();
count++;
} return result;
}
// create a `counter`
// while `counter` is less than length of array
// begin loop
// use `counter` to identify the `current Person` in the array
// get `string Representation` of `currentPerson`
// append `stringRepresentation` to `result` variable
// end loop
return result;
}
public String forLoop() {
String result = "";
//int count = 0;
for (int counter = 0 ; counter < personArray.length; counter++) {
// count++;
String currentPerson = personArray[counter].toString(); //use counter to identify current person
result += currentPerson;
}
// identify initial value
// identify terminal condition
// identify increment
// use the above clauses to declare for-loop signature
// begin loop
// use `counter` to identify the `current Person` in the array
// get `string Representation` of `currentPerson`
// append `stringRepresentation` to `result` variable
// end loop
return result;
}
public String forEachLoop() {
String result = "";
int i = 0;
Person person = personArray[i];
for (Person currentPerson : personArray) { //for each loop (variable , array)
String newPerson = currentPerson.toString();
result += newPerson;
}
// identify array's type
// identify array's variable-name
// use the above discoveries to declare for-each-loop signature
// begin loop
// get `string Representation` of `currentPerson`
// append `stringRepresentation` to `result` variable
// end loop
return result;
}
public Person[] getPersonArray() {
return personArray;
}
}