瀏覽代碼

finished lab

Saurav Kamath 6 年之前
父節點
當前提交
a25540cca2
共有 1 個文件被更改,包括 11 次插入25 次删除
  1. 11
    25
      src/main/java/com/zipcodewilmington/PersonHandler.java

+ 11
- 25
src/main/java/com/zipcodewilmington/PersonHandler.java 查看文件

@@ -11,16 +11,12 @@ public class PersonHandler {
11 11
     }
12 12
 
13 13
     public String whileLoop() {
14
+        int count = 0;
14 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 20
         return result;
25 21
     }
26 22
 
@@ -28,17 +24,11 @@ public class PersonHandler {
28 24
 
29 25
     public String forLoop() {
30 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 32
         return result;
43 33
     }
44 34
 
@@ -46,15 +36,11 @@ public class PersonHandler {
46 36
 
47 37
     public String forEachLoop() {
48 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 44
         return result;
59 45
     }
60 46