From 8951daed66c4c745b09d78e64f3b346001a6ada0 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 29 Jun 2021 20:18:42 -0400 Subject: [PATCH] Passed all tests --- .../com/zipcodewilmington/PersonHandler.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..3d43943 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -13,13 +13,17 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { String result = ""; // create a `counter` + int counter = 0; // while `counter` is less than length of array + while(counter < personArray.length) { // begin loop - - // use `counter` to identify the `current Person` in the array - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable - + String currentPerson = personArray[counter].toString(); + result += currentPerson; + counter++; + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + } // end loop 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 + for(int i = 0; i < personArray.length; i++) { + // 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 + // use `counter` to identify the `current Person` in the array + String stringRepresentation = personArray[i].toString(); + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable // end loop - + result += stringRepresentation; + } return result; } @@ -49,12 +55,14 @@ public String forEachLoop() { // identify array's type // identify array's variable-name - // use the above discoveries to declare for-each-loop signature + for(Person person : personArray) { + // use the above discoveries to declare for-each-loop signature // begin loop - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable + result += person.toString(); + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable // end loop - + } return result; }