diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..a37ab1f 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -11,27 +11,47 @@ public PersonHandler(Person[] personArray) { } public String whileLoop() { + + int counter = 0; + String result = ""; + while (counter < personArray.length) { + result += personArray[counter].toString(); + counter++; + + } + + return 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; - } + + public String forLoop() { + + int i = 0; String result = ""; + for (i = 0; i < personArray.length; i++) { + result += personArray[i].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 @@ -39,13 +59,13 @@ public String forLoop() { // append `stringRepresentation` to `result` variable // end loop - return result; - } - public String forEachLoop() { - String result = ""; + + + public String forEachLoop() { + // identify array's type // identify array's variable-name @@ -54,12 +74,25 @@ public String forEachLoop() { // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable // end loop + String result = ""; + + + + for (Person i : personArray) { + + + result += i.toString(); + } + return result; } public Person[] getPersonArray() { + + + return personArray; } }