diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..1305eef 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -1,5 +1,8 @@ package com.zipcodewilmington; +import java.lang.reflect.Array; +import java.util.ArrayList; + /** * Created by leon on 1/24/18. */ @@ -11,21 +14,31 @@ public PersonHandler(Person[] personArray) { } public String whileLoop() { - String result = ""; + // create a `counter` // while `counter` is less than length of array - // begin loop + // begin loop + + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + + // end loop + + String result = ""; + int i = 0; + while (i < personArray.length) { + + String currentPerson = personArray[i].toString(); + result += currentPerson; - // use `counter` to identify the `current Person` in the array - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable + i++; + } - // end loop return result; } - public String forLoop() { String result = ""; // identify initial value @@ -33,33 +46,37 @@ public String forLoop() { // 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 - + // 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++) { + String currentPerson = personArray[i].toString(); + result += currentPerson; + } return result; } - 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 + // begin loop + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + // end loop - return result; - } + for (Person people : personArray) { + String currentPeople = people.toString(); + result+=currentPeople; + } + return result; - public Person[] getPersonArray() { - return personArray; } } +