diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..e6b0588 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -13,14 +13,18 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { String result = ""; // create a `counter` + int counter = 0; // 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 - + while (counter < personArray.length) { + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + String currentPerson = String.format("%s", personArray[counter]); + // append `stringRepresentation` to `result` variable + result += currentPerson; // end loop + counter += 1; + } return result; } @@ -31,14 +35,16 @@ public String forLoop() { // 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` + for (int i = 0; i < personArray.length; i++) { + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + String currentPerson = String.format("%s",personArray[i]); // append `stringRepresentation` to `result` variable + result += currentPerson; // end loop - + } return result; } @@ -48,11 +54,13 @@ 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 + for (Person currentPerson : personArray) { + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + result += String.format("%s", currentPerson); + } // end loop return result;