-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPersonHandler.java
More file actions
78 lines (60 loc) · 2.1 KB
/
PersonHandler.java
File metadata and controls
78 lines (60 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.zipcodewilmington;
import java.util.Arrays;
/**
* Created by leon on 1/24/18.
*/
public class PersonHandler {
private final Person[] personArray;
public PersonHandler(Person[] personArray) {
this.personArray = personArray;
}
public String whileLoop() {
StringBuilder result = new StringBuilder();
// create a `counter`
int counter = 0;
// while `counter` is less than length of array
while(counter< personArray.length){
// begin loop
// use `counter` to identify the `current Person` in the array
// get `string Representation` of `currentPerson`
// append `stringRepresentation` to `result` variable
result.append(personArray[counter].toString());
counter++;
}// end loop
return result.toString();
}
public String forLoop() {
String result = "";
// identify initial value
// identify terminal condition
// identify increment
// use the above clauses to declare for-loop signature
// begin loop
// use `counter` to identify the `current Person` in the array
// get `string Representation` of `currentPerson`
// append `stringRepresentation` to `result` variable
// end loop
for(int i=0;i< personArray.length;i++)
{
result+=personArray[i].toString();
}
return result;
}
public String forEachLoop() {
StringBuilder result = new StringBuilder();
// identify array's type
// identify array's variable-name
// use the above discoveries to declare for-each-loop signature
// begin loop
// get `string Representation` of `currentPerson`
// append `stringRepresentation` to `result` variable
// end loop
for(Person strArray: personArray){
result.append(strArray);
}
return result.toString();
}
public Person[] getPersonArray() {
return personArray;
}
}