From c6d1ee360a664effbfa9a35d9f1c8b0364c1e6b2 Mon Sep 17 00:00:00 2001 From: Greg Donnelly Date: Mon, 1 Mar 2021 16:02:09 -0500 Subject: [PATCH 1/4] While Loop passes tests --- .../java/com/zipcodewilmington/PersonHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..10cf610 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -11,9 +11,15 @@ public PersonHandler(Person[] personArray) { } public String whileLoop() { - String result = ""; + StringBuilder result = new StringBuilder(); // create a `counter` + double counter = 0; // while `counter` is less than length of array + while (counter < personArray.length) { + Person newStr = personArray[(int) counter]; + result.append(newStr); + counter ++; + } // begin loop // use `counter` to identify the `current Person` in the array @@ -21,7 +27,8 @@ public String whileLoop() { // append `stringRepresentation` to `result` variable // end loop - return result; + String output = result.toString(); + return output; } From 5bced69cf58ef76786e7dbe209c19342f9a36211 Mon Sep 17 00:00:00 2001 From: Greg Donnelly Date: Mon, 1 Mar 2021 16:41:48 -0500 Subject: [PATCH 2/4] for loop works --- src/main/java/com/zipcodewilmington/PersonHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 10cf610..bbf348c 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -38,15 +38,17 @@ public String forLoop() { // identify initial value // identify terminal condition // identify increment - + for (int i = 0; i < personArray.length; i++) { + Person newStr = personArray[i]; + result = result + newStr; + } + return result; // 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 - - return result; } @@ -55,7 +57,7 @@ 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` From 1bd3d59335ef0de58bbd9833569c7cf62d216513 Mon Sep 17 00:00:00 2001 From: Greg Donnelly Date: Mon, 1 Mar 2021 19:27:15 -0500 Subject: [PATCH 3/4] All three loops passing tests --- src/main/java/com/zipcodewilmington/PersonHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index bbf348c..7de0809 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -57,7 +57,9 @@ public String forEachLoop() { String result = ""; // identify array's type // identify array's variable-name - + for (Person person : personArray) { + result = result + person; + } // use the above discoveries to declare for-each-loop signature // begin loop // get `string Representation` of `currentPerson` From 91b6d4288deee5d765130cc9acf758955a7b5075 Mon Sep 17 00:00:00 2001 From: Greg Donnelly Date: Mon, 1 Mar 2021 19:29:27 -0500 Subject: [PATCH 4/4] all tests passing and removed the comments so it looks nicer --- .../com/zipcodewilmington/PersonHandler.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 7de0809..de9fd37 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -12,21 +12,12 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { StringBuilder result = new StringBuilder(); - // create a `counter` double counter = 0; - // while `counter` is less than length of array while (counter < personArray.length) { Person newStr = personArray[(int) counter]; result.append(newStr); counter ++; } - // 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 output = result.toString(); return output; } @@ -35,37 +26,20 @@ public String whileLoop() { public String forLoop() { String result = ""; - // identify initial value - // identify terminal condition - // identify increment for (int i = 0; i < personArray.length; i++) { Person newStr = personArray[i]; result = result + newStr; } return result; - // 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 } public String forEachLoop() { String result = ""; - // identify array's type - // identify array's variable-name for (Person person : personArray) { result = result + person; } - // use the above discoveries to declare for-each-loop signature - // begin loop - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable - // end loop - return result; }