From 52b6de217449ab08ad2780bf7bda014138ad4c2c Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 29 Jun 2021 18:27:57 -0400 Subject: [PATCH] Passed all test cases --- .../com/zipcodewilmington/PersonHandler.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..7770119 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -1,5 +1,7 @@ package com.zipcodewilmington; +import java.lang.reflect.Array; + /** * Created by leon on 1/24/18. */ @@ -16,6 +18,15 @@ public String whileLoop() { // while `counter` is less than length of array // begin loop + // created the code using 2 kinds of iteration -- why '.append' when this code works? + /* for (int counter = 0; counter < personArray.length; counter++) { + result += personArray[counter]; + } */ + int counter = 0; + while (counter < personArray.length) { + result += personArray[counter]; + counter++; + } // use `counter` to identify the `current Person` in the array // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable @@ -31,7 +42,9 @@ public String forLoop() { // identify initial value // identify terminal condition // identify increment - + for (int counter = 0; counter < personArray.length; counter++) { + result += personArray[counter]; + } // use the above clauses to declare for-loop signature // begin loop // use `counter` to identify the `current Person` in the array @@ -42,13 +55,16 @@ public String forLoop() { return result; } - +// how do you do forEachLoops public String forEachLoop() { String result = ""; + String stringRepresentation = ""; // identify array's type // identify array's variable-name - + for (Person theEnd: personArray) { + result += theEnd; + } // use the above discoveries to declare for-each-loop signature // begin loop // get `string Representation` of `currentPerson`