From a051ed1b873e6d65935d2a038ee374e655e1ba5f Mon Sep 17 00:00:00 2001 From: Dipinti Date: Wed, 30 Jun 2021 12:26:49 -0400 Subject: [PATCH] passed all tests pf personHandler --- .../com/zipcodewilmington/PersonHandler.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..22773ae 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.util.Arrays; + /** * Created by leon on 1/24/18. */ @@ -11,17 +13,21 @@ public PersonHandler(Person[] personArray) { } public String whileLoop() { - String result = ""; + StringBuilder result = new StringBuilder(); // create a `counter` + int counter = 0; // while `counter` is less than length of array + while(counter< personArray.length){ // begin loop - // use `counter` to identify the `current Person` in the array - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + result.append(personArray[counter].toString()); + counter++; - // end loop - return result; + }// end loop + return result.toString(); } @@ -38,6 +44,10 @@ public String forLoop() { // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable // end loop + for(int i=0;i< personArray.length;i++) + { + result+=personArray[i].toString(); + } return result; } @@ -45,7 +55,7 @@ public String forLoop() { public String forEachLoop() { - String result = ""; + StringBuilder result = new StringBuilder(); // identify array's type // identify array's variable-name @@ -54,8 +64,11 @@ public String forEachLoop() { // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable // end loop + for(Person strArray: personArray){ + result.append(strArray); + } - return result; + return result.toString(); }