From 9ecbb98b9adc0258af4c505f766dd9977ff96d97 Mon Sep 17 00:00:00 2001 From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com> Date: Fri, 2 Jul 2021 18:30:01 -0400 Subject: [PATCH 1/2] Was able to get the whileLoop to pass, 'use counter' was meant //personArray[count] --- .../com/zipcodewilmington/PersonHandler.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..7ed0989 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -12,9 +12,12 @@ 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` @@ -28,12 +31,17 @@ public String whileLoop() { public String forLoop() { String result = ""; - // identify initial value - // identify terminal condition - // identify increment + 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 + + + + + + } + + + - // 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 From 03b01b4ab70e6168eaa3a4449511738fe3018a9a Mon Sep 17 00:00:00 2001 From: TatianaDeAngelo <85692272+TatianaDeAngelo@users.noreply.github.com> Date: Fri, 2 Jul 2021 19:47:12 -0400 Subject: [PATCH 2/2] all tests passed --- .../com/zipcodewilmington/PersonHandler.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 7ed0989..ef3ad1d 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -17,8 +17,6 @@ public String whileLoop() { 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 @@ -31,17 +29,10 @@ public String whileLoop() { public String forLoop() { String result = ""; - 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 - - - - - + 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 @@ -54,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`