123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Created by leon on 1/24/18.
  3. */
  4. public class PersonHandler {
  5. private final Person[] personArray;
  6. public PersonHandler(Person[] personArray) {
  7. this.personArray = personArray;
  8. }
  9. public String whileLoop() {
  10. String result = "";
  11. // assume there is a `counter`
  12. // while `counter` is less than length of array
  13. // begin loop
  14. // use `counter` to identify the `current Person` in the array
  15. // get `string Representation` of `currentPerson`
  16. // append `stringRepresentation` to `result` variable
  17. // end loop
  18. return result;
  19. }
  20. public String forLoop() {
  21. String result = "";
  22. // identify initial value
  23. // identify terminal condition
  24. // identify increment
  25. // use the above clauses to declare for-loop signature
  26. // begin loop
  27. // use `counter` to identify the `current Person` in the array
  28. // get `string Representation` of `currentPerson`
  29. // append `stringRepresentation` to `result` variable
  30. // end loop
  31. return result;
  32. }
  33. public String forEachLoop() {
  34. String result = "";
  35. // identify array's type
  36. // identify array's variable-name
  37. // use the above discoveries to declare for-each-loop signature
  38. // begin loop
  39. // get `string Representation` of `currentPerson`
  40. // append `stringRepresentation` to `result` variable
  41. // end loop
  42. return result;
  43. }
  44. public Person[] getPersonArray() {
  45. return personArray;
  46. }
  47. }