Browse Source

finished lab

Saurav Kamath 6 years ago
parent
commit
a25540cca2
1 changed files with 11 additions and 25 deletions
  1. 11
    25
      src/main/java/com/zipcodewilmington/PersonHandler.java

+ 11
- 25
src/main/java/com/zipcodewilmington/PersonHandler.java View File

11
     }
11
     }
12
 
12
 
13
     public String whileLoop() {
13
     public String whileLoop() {
14
+        int count = 0;
14
         String result = "";
15
         String result = "";
15
-        // assume there is a `counter`
16
-        // while `counter` is less than length of array
17
-            // begin loop
18
-
19
-                // use `counter` to identify the `current Person` in the array
20
-                // get `string Representation` of `currentPerson`
21
-                // append `stringRepresentation` to `result` variable
22
-
23
-            // end loop
16
+        while(count < personArray.length) {
17
+            result= result.concat(personArray[count].toString());
18
+            count ++;
19
+        }
24
         return result;
20
         return result;
25
     }
21
     }
26
 
22
 
28
 
24
 
29
     public String forLoop() {
25
     public String forLoop() {
30
         String result = "";
26
         String result = "";
31
-        // identify initial value
32
-        // identify terminal condition
33
-        // identify increment
27
+        for (int i= 0; i < personArray.length; i++){
34
 
28
 
35
-        // use the above clauses to declare for-loop signature
36
-            // begin loop
37
-                // use `counter` to identify the `current Person` in the array
38
-                // get `string Representation` of `currentPerson`
39
-                // append `stringRepresentation` to `result` variable
40
-            // end loop
29
+            result= result.concat(personArray[i].toString());
41
 
30
 
31
+            }
42
         return result;
32
         return result;
43
     }
33
     }
44
 
34
 
46
 
36
 
47
     public String forEachLoop() {
37
     public String forEachLoop() {
48
         String result = "";
38
         String result = "";
49
-        // identify array's type
50
-        // identify array's variable-name
39
+        for (Person person: personArray) {
51
 
40
 
52
-        // use the above discoveries to declare for-each-loop signature
53
-            // begin loop
54
-                // get `string Representation` of `currentPerson`
55
-                // append `stringRepresentation` to `result` variable
56
-            // end loop
41
+            result= result.concat(person.toString());
57
 
42
 
43
+        }
58
         return result;
44
         return result;
59
     }
45
     }
60
 
46