From 4651280a5d5ad66b9ec36df6f604280074e4acd3 Mon Sep 17 00:00:00 2001 From: Manny Date: Wed, 30 Jun 2021 00:17:48 -0400 Subject: [PATCH] Manny finished personDetails lab --- .../com/zipcodewilmington/PersonHandler.java | 83 ++++++++++++------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..9333c98 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -13,53 +13,74 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { String result = ""; // create a `counter` + int counter = 0; // 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 (counter < this.personArray.length) { // begin loop + Person currentPerson = this.personArray[counter]; // use `counter` to identify the `current Person` in the array + String stringRepresentation = currentPerson.toString(); // get `string Representation` of `currentPerson` + result += stringRepresentation; // append `stringRepresentation` to `result` variable + counter++; // end loop + } return result; } + /* + while (counter < personArray.length) { + String currentPerson = personArray[counter].toString(); + result += currentPerson; + counter++; + } + return result; + } + */ + public String forLoop () { + String result = ""; + // identify initial value + // identify terminal condition + // identify increment - - public String forLoop() { - String result = ""; - // identify initial value - // identify terminal condition - // identify increment - - // use the above clauses to declare for-loop signature + // 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 + //for (int i = 0; i < personArray.length; i++) { + + //} + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable // end loop - return result; - } + for (int i = 0; i < personArray.length; i++) { + Person personNow = personArray[i]; + result += personNow.toString(); + } + return result; + } - public String forEachLoop() { - String result = ""; - // identify array's type - // identify array's variable-name + public String forEachLoop () { + String result = ""; + // identify array's type + // identify array's variable-name - // use the above discoveries to declare for-each-loop signature + + // use the above discoveries to declare for-each-loop signature // begin loop - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable // end loop + for (Person person: personArray ) { + String personNow = person.toString(); + result += personNow; + } - return result; - } + return result; + } - public Person[] getPersonArray() { - return personArray; + public Person[] getPersonArray () { + return personArray; + } } -} +