#28 LA

Open
chu1ta26 wants to merge 1 commits from chu1ta26/CR-MesoLabs-Arrays-PersonDetails:master into master
1 changed files with 15 additions and 1 deletions
  1. 15
    1
      src/main/java/com/zipcodewilmington/PersonHandler.java

+ 15
- 1
src/main/java/com/zipcodewilmington/PersonHandler.java View File

12
 
12
 
13
     public String whileLoop() {
13
     public String whileLoop() {
14
         String result = "";
14
         String result = "";
15
+        int counter = 0;
15
         // assume there is a `counter`
16
         // assume there is a `counter`
16
         // while `counter` is less than length of array
17
         // while `counter` is less than length of array
17
             // begin loop
18
             // begin loop
19
+        while (counter < personArray.length){
20
+
21
+
22
+
18
 
23
 
19
                 // use `counter` to identify the `current Person` in the array
24
                 // use `counter` to identify the `current Person` in the array
20
                 // get `string Representation` of `currentPerson`
25
                 // get `string Representation` of `currentPerson`
21
                 // append `stringRepresentation` to `result` variable
26
                 // append `stringRepresentation` to `result` variable
22
-
27
+        result= result.concat(personArray[counter].toString());
28
+        counter ++;
29
+        }
23
             // end loop
30
             // end loop
24
         return result;
31
         return result;
25
     }
32
     }
28
 
35
 
29
     public String forLoop() {
36
     public String forLoop() {
30
         String result = "";
37
         String result = "";
38
+        for (int i= 0; i < personArray.length; i++){
39
+            result= result.concat(personArray[i].toString());
40
+        }
31
         // identify initial value
41
         // identify initial value
32
         // identify terminal condition
42
         // identify terminal condition
33
         // identify increment
43
         // identify increment
48
         String result = "";
58
         String result = "";
49
         // identify array's type
59
         // identify array's type
50
         // identify array's variable-name
60
         // identify array's variable-name
61
+        for (Person value: personArray) {
62
+            result= result.concat(value.toString());
63
+        }
51
 
64
 
52
         // use the above discoveries to declare for-each-loop signature
65
         // use the above discoveries to declare for-each-loop signature
53
             // begin loop
66
             // begin loop
60
 
73
 
61
 
74
 
62
     public Person[] getPersonArray() {
75
     public Person[] getPersonArray() {
76
+
63
         return personArray;
77
         return personArray;
64
     }
78
     }
65
 }
79
 }