#32 person details finished

Offen
jbedolla40 möchte 1 Commits von jbedolla40/CR-MesoLabs-Arrays-PersonDetails:master nach master zusammenführen
1 geänderte Dateien mit 23 neuen und 1 gelöschten Zeilen
  1. 23
    1
      src/main/java/com/zipcodewilmington/PersonHandler.java

+ 23
- 1
src/main/java/com/zipcodewilmington/PersonHandler.java Datei anzeigen

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