From 21049131be407c188dbf9d219ce9cb530456b068 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Wed, 3 Nov 2021 12:47:33 -0400 Subject: [PATCH 1/3] completed lab --- .../com/zipcodewilmington/PersonHandler.java | 59 +++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 6970947..fc263f6 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -13,14 +13,20 @@ public PersonHandler(Person[] personArray) { public String whileLoop() { String result = ""; // 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 - - // end loop + Person currentPerson = personArray[counter]; + String strCurrentPerson = currentPerson.toString(); + result += strCurrentPerson; + counter++; + } + // use `counter` to identify the `current Person` in the array + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + + // end loop return result; } @@ -28,16 +34,23 @@ public String whileLoop() { public String forLoop() { String result = ""; + int counter = 0; // identify initial value // identify terminal condition // identify increment + for(counter = 0; counter < personArray.length; counter++ ) { + Person currentPerson = personArray[counter]; + String strCurrentPerson = currentPerson.toString(); + result += strCurrentPerson; + + } // 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 + // 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 +59,24 @@ public String forLoop() { public String forEachLoop() { String result = ""; - // identify array's type - // identify array's variable-name + // identify array's type -- Person + // identify array's variable-name -- personArray // 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) { + + + String strCurrentPerson = person.toString(); + result += strCurrentPerson; + } + + + + + // begin loop + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + // end loop return result; } @@ -62,4 +85,4 @@ public String forEachLoop() { public Person[] getPersonArray() { return personArray; } -} +} \ No newline at end of file From aa6b4c17273cfd910845fdb16168c577771d229e Mon Sep 17 00:00:00 2001 From: Ellis John Date: Sun, 14 Nov 2021 19:35:14 -0500 Subject: [PATCH 2/3] additional changes while loop --- .../java/com/zipcodewilmington/Person.java | 2 +- .../com/zipcodewilmington/PersonHandler.java | 63 +++++++++++-------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/Person.java b/src/main/java/com/zipcodewilmington/Person.java index 6e84ed0..cc90725 100644 --- a/src/main/java/com/zipcodewilmington/Person.java +++ b/src/main/java/com/zipcodewilmington/Person.java @@ -20,7 +20,7 @@ public String getLastName() { return lastName; } - @Override + @Override // toString() gives us the memory address innately, we overrided it to give us the 2 strings instead public String toString() { return new StringBuilder() .append("\nMy first name is " + firstName) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index fc263f6..7389d65 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -11,38 +11,52 @@ public PersonHandler(Person[] personArray) { } public String whileLoop() { + + + // just another attempt String result = ""; - // create a `counter` - int counter = 0; - // while `counter` is less than length of array - while (counter < personArray.length) { - // begin loop - Person currentPerson = personArray[counter]; - String strCurrentPerson = currentPerson.toString(); - result += strCurrentPerson; - counter++; - } - // use `counter` to identify the `current Person` in the array - // get `string Representation` of `currentPerson` - // append `stringRepresentation` to `result` variable + int i = 0; - // end loop + while (i < this.personArray.length) { + Person currentPerson = personArray[i]; // notice the Person class used here... + result = result + currentPerson; + i++; + } return result; - } +// // create empty string which we can place +// String result = ""; +// // create a `counter` +// int counter = 0; +// // while `counter` is less than length of array +// while (counter < this.personArray.length) { +// // begin loop +// Person currentPerson = personArray[counter]; // currentPerson variable is the current position in the personArray +// String strCurrentPerson = currentPerson.toString(); // create variable to save currentPerson.toString(); +// result = result + strCurrentPerson; // adding strCurrentPerson to result +// counter++; +// } +// // use `counter` to identify the `current Person` in the array +// // get `string Representation` of `currentPerson` +// // append `stringRepresentation` to `result` variable +// +// // end loop +// return result; + } + + public String forLoop() { String result = ""; - int counter = 0; + int counter; // identify initial value // identify terminal condition // identify increment - for(counter = 0; counter < personArray.length; counter++ ) { - Person currentPerson = personArray[counter]; - String strCurrentPerson = currentPerson.toString(); - result += strCurrentPerson; - + for (counter = 0; counter < personArray.length; counter++) { + Person currentPerson = personArray[counter]; + String strCurrentPerson = currentPerson.toString(); + result += strCurrentPerson; } // use the above clauses to declare for-loop signature @@ -56,23 +70,22 @@ public String forLoop() { } - public String forEachLoop() { String result = ""; // identify array's type -- Person // identify array's variable-name -- personArray // use the above discoveries to declare for-each-loop signature - for (Person person : personArray) { + // SO, FOR EACH LOOPS WILL PERFORM THE CODE ON EVERY THING IN THE SET--ITLL GO THROUGH EVERY SINGLE ONE + for (Person person : personArray) { // for each currentPerson in personArray do something String strCurrentPerson = person.toString(); + result += strCurrentPerson; } - - // begin loop // get `string Representation` of `currentPerson` // append `stringRepresentation` to `result` variable From 2600de2b3f1658d2512886e18ec06d85b84f1ad2 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Sun, 14 Nov 2021 19:57:49 -0500 Subject: [PATCH 3/3] reviewing --- .../com/zipcodewilmington/PersonHandler.java | 74 +++++++++++++------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/PersonHandler.java b/src/main/java/com/zipcodewilmington/PersonHandler.java index 7389d65..635509d 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -48,42 +48,70 @@ public String whileLoop() { public String forLoop() { + + // just another attempt String result = ""; - int counter; - // identify initial value - // identify terminal condition - // identify increment - for (counter = 0; counter < personArray.length; counter++) { - Person currentPerson = personArray[counter]; - String strCurrentPerson = currentPerson.toString(); - result += strCurrentPerson; + + for (int i = 0; i < personArray.length; i++) { + result = result + personArray[i]; } - // 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; + + +// +// String result = ""; +// int counter; +// // identify initial value +// // identify terminal condition +// // identify increment +// for (counter = 0; counter < personArray.length; counter++) { +// Person currentPerson = personArray[counter]; +// String strCurrentPerson = currentPerson.toString(); +// result += strCurrentPerson; +// +// } +// // 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; } public String forEachLoop() { + + // just another attempt String result = ""; + int i = 0; - // identify array's type -- Person - // identify array's variable-name -- personArray - // use the above discoveries to declare for-each-loop signature + for (Person person : personArray) { + result = result + personArray[i]; + i++; + } + + return result; - // SO, FOR EACH LOOPS WILL PERFORM THE CODE ON EVERY THING IN THE SET--ITLL GO THROUGH EVERY SINGLE ONE - for (Person person : personArray) { // for each currentPerson in personArray do something - String strCurrentPerson = person.toString(); - result += strCurrentPerson; - } + +// String result = ""; +// +// // identify array's type -- Person +// // identify array's variable-name -- personArray +// // use the above discoveries to declare for-each-loop signature +// +// // SO, FOR EACH LOOPS WILL PERFORM THE CODE ON EVERY THING IN THE SET--ITLL GO THROUGH EVERY SINGLE ONE +// for (Person person : personArray) { // for each currentPerson in personArray do something +// +// String strCurrentPerson = person.toString(); +// +// result += strCurrentPerson; +// } // begin loop @@ -91,7 +119,7 @@ public String forEachLoop() { // append `stringRepresentation` to `result` variable // end loop - return result; +// return result; }