From 3d44e489e44e7b731baf548a871a96e87a2aa9c6 Mon Sep 17 00:00:00 2001 From: jorge Date: Wed, 3 Mar 2021 23:13:23 -0500 Subject: [PATCH] Passed all test --- .../com/zipcodewilmington/PersonHandler.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..f77b8f0 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 com.sun.tools.javac.util.ArrayUtils; + /** * Created by leon on 1/24/18. */ @@ -12,15 +14,15 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { String result = ""; - // create a `counter` + int i =0 ;// create a `counter` // while `counter` is less than length of array - // begin loop - - // use `counter` to identify the `current Person` in the array - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable + while (i < personArray.length) { - // end loop + // begin loop + result = result.concat(personArray[i].toString());// use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + i++; // append `stringRepresentation` to `result` variable + }// end loop return result; } @@ -28,16 +30,16 @@ public String whileLoop() { public String forLoop() { String result = ""; - // identify initial value - // identify terminal condition - // identify increment + int value = 0;// identify initial value + for(value = 0; value < personArray.length; value++){ // identify terminal condition - // 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 + // identify increment + // use the above clauses to declare for-loop signature + result = result.concat(personArray[value].toString()); // 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; } @@ -46,14 +48,13 @@ public String forLoop() { 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 + for (Person person : personArray) { // for each person in personArray + // identify array's variable-name + // use the above discoveries to declare for-each-loop signature + result = result + person.toString(); // begin loop + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + } // end loop return result; }