#32 person details finished

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

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

6
 public class PersonHandler {
6
 public class PersonHandler {
7
     private final Person[] personArray;
7
     private final Person[] personArray;
8
 
8
 
9
-    public PersonHandler(Person[] personArray) {
9
+    public PersonHandler(Person[] personArray)
10
+    {
10
         this.personArray = personArray;
11
         this.personArray = personArray;
11
     }
12
     }
12
 
13
 
13
     public String whileLoop() {
14
     public String whileLoop() {
14
         String result = "";
15
         String result = "";
16
+        int counter = 0;
17
+        while(counter<personArray.length)
18
+        {
19
+        String stringRepresentation = personArray[counter].toString();
20
+        result+=stringRepresentation;
21
+        counter++;
22
+        }
23
+
24
+
15
         // assume there is a `counter`
25
         // assume there is a `counter`
16
         // while `counter` is less than length of array
26
         // while `counter` is less than length of array
17
             // begin loop
27
             // begin loop
28
 
38
 
29
     public String forLoop() {
39
     public String forLoop() {
30
         String result = "";
40
         String result = "";
41
+        int counter = 0;
31
         // identify initial value
42
         // identify initial value
32
         // identify terminal condition
43
         // identify terminal condition
33
         // identify increment
44
         // identify increment
45
+        for(int i=0; i < personArray.length; i++ )
46
+        {
47
+            String stringRepresentation = personArray[counter].toString();
48
+            result+=stringRepresentation;
49
+            counter++;
50
+        }
34
 
51
 
35
         // use the above clauses to declare for-loop signature
52
         // use the above clauses to declare for-loop signature
36
             // begin loop
53
             // begin loop
48
         String result = "";
65
         String result = "";
49
         // identify array's type
66
         // identify array's type
50
         // identify array's variable-name
67
         // identify array's variable-name
68
+        for(Person a: personArray)
69
+        {
70
+            String  stringRepresentation = a.toString();
71
+            result+=stringRepresentation;
72
+        }
51
 
73
 
52
         // use the above discoveries to declare for-each-loop signature
74
         // use the above discoveries to declare for-each-loop signature
53
             // begin loop
75
             // begin loop