Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 20 additions & 29 deletions src/main/java/com/zipcodewilmington/PersonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,40 @@ public PersonHandler(Person[] personArray) {

public String whileLoop() {
String 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
StringBuilder names = new StringBuilder();
int counter = 0;
while (counter < personArray.length){
String currentPerson = personArray[counter].toString();
result += currentPerson;
counter++;
}
return result;
}




public String forLoop() {
String result = "";
// 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

StringBuilder names = new StringBuilder();
for (int counter = 0; counter < personArray.length; counter++){
String currentPerson = personArray[counter].toString();
result += currentPerson;
}
return result;
}



public String forEachLoop() {
String result = "";
// 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

int i = 0;
Person currentPerson = personArray[i];
for(Person name : personArray) {
currentPerson = name;
result += currentPerson;
i++;
}
return result;
}

Expand Down