Newer
Older
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
package fr.univamu.progav.td2;
import java.util.List;
public class People {
private final String name;
private final int age;
public People(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
/** Decides whether the list contains a 25-year-old "Charlie"
* @param peopleList
* @return true if a 25-year-old charlie is in the list
*/
public static int whereIsCharlie(List<People> peopleList) {
People charlie = new People("Charlie", 25);
int count = 0;
for (People p : peopleList) {
if (p == charlie) {
return count;
}
count++;
}
return -1; // Charlie is not here.
}
@Override
public String toString() {
return this.name;
}
}