diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..ef3ad1d 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -12,10 +12,11 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { String result = ""; - // create a `counter` - // while `counter` is less than length of array - // begin loop - + int count = 0 ; // create a `counter` + while (count < personArray.length) { // while `counter` is less than length of array + result += personArray[count].toString(); + count++; // begin loop + } // use `counter` to identify the `current Person` in the array // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable @@ -28,12 +29,10 @@ public String whileLoop() { public String forLoop() { String result = ""; - // identify initial value - // identify terminal condition - // identify increment - - // use the above clauses to declare for-loop signature - // begin loop + for (int i = 0; i < personArray.length; i++) {// identify initial value // identify terminal condition // identify increment // use the above clauses to declare for-loop signature // begin loop + result += personArray[i].toString(); + //i++ is inside for () does not need to be repeated again + } // use `counter` to identify the `current Person` in the array // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable @@ -46,9 +45,12 @@ public String forLoop() { public String forEachLoop() { String result = ""; - // identify array's type - // identify array's variable-name + int i = 0; + for (Person name : personArray) { + result += personArray[i].toString(); + i++; + } // use the above discoveries to declare for-each-loop signature // begin loop // get `string Representation` of `currentPerson`