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
52 changes: 39 additions & 13 deletions src/main/java/com/zipcodewilmington/PersonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
public class PersonHandler {
private final Person[] personArray;

public PersonHandler(Person[] personArray) {
this.personArray = personArray;
public PersonHandler(Person[] personArray) { this.personArray = personArray;
}

public String whileLoop() {
String result = "";
StringBuilder stringRepresentation = new StringBuilder();
int counter =0;
while (counter < personArray.length) {
Person currentPerson =personArray[counter];
stringRepresentation.append(currentPerson);
counter ++;
}
String output = stringRepresentation.toString();
// create a `counter`
// while `counter` is less than length of array
// begin loop
Expand All @@ -21,31 +27,51 @@ public String whileLoop() {
// append `stringRepresentation` to `result` variable

// end loop
return result;
return output;
}



public String forLoop() {
String result = "";
StringBuilder stringRepresentation = new StringBuilder();
int counter = 0;
for (counter = 0; counter < personArray.length; counter++) {
Person currentPerson = personArray[counter];
stringRepresentation.append(currentPerson);

}

String result = stringRepresentation.toString();
return 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
// 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 = "";
for ( Person name : personArray ){
String currentPerson = name.toString();
result = result + currentPerson;


}
return result;
}


// identify array's type
// identify array's variable-name

Expand All @@ -55,8 +81,8 @@ public String forEachLoop() {
// append `stringRepresentation` to `result` variable
// end loop

return result;
}




public Person[] getPersonArray() {
Expand Down