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 6970947..635509d 100644 --- a/src/main/java/com/zipcodewilmington/PersonHandler.java +++ b/src/main/java/com/zipcodewilmington/PersonHandler.java @@ -11,55 +11,119 @@ public PersonHandler(Person[] personArray) { } public String whileLoop() { - String result = ""; - // 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 - // end loop + // just another attempt + String result = ""; + int i = 0; + + 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() { + + // just another attempt String result = ""; - // identify initial value - // identify terminal condition - // identify increment - // 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 + for (int i = 0; i < personArray.length; i++) { + result = result + personArray[i]; + + } 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 = ""; - // identify array's type - // identify array's variable-name + int i = 0; - // 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) { + result = result + personArray[i]; + i++; + } return result; + + + + +// 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 + // get `string Representation` of `currentPerson` + // append `stringRepresentation` to `result` variable + // end loop + +// return result; } public Person[] getPersonArray() { return personArray; } -} +} \ No newline at end of file