diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..2fdcf19 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -12,33 +12,26 @@ 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; } @@ -46,15 +39,13 @@ 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 - + int i = 0; + Person currentPerson = personArray[i]; + for(Person name : personArray) { + currentPerson = name; + result += currentPerson; + i++; + } return result; }