diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..de9fd37 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -11,34 +11,25 @@ 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 - return result; + StringBuilder result = new StringBuilder(); + double counter = 0; + while (counter < personArray.length) { + Person newStr = personArray[(int) counter]; + result.append(newStr); + counter ++; + } + String output = result.toString(); + return output; } 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 - + for (int i = 0; i < personArray.length; i++) { + Person newStr = personArray[i]; + result = result + newStr; + } return result; } @@ -46,15 +37,9 @@ public String forLoop() { 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 - + for (Person person : personArray) { + result = result + person; + } return result; }