-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
47 lines (38 loc) · 1.11 KB
/
Person.java
File metadata and controls
47 lines (38 loc) · 1.11 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
public class Person implements Comparable<Person> {
private String name;
private int birthYear;
public Person() {
this.name = "";
this.birthYear = 0;
}
public Person(String name, int birthYear) {
this.name = name;
this.birthYear = birthYear;
}
public String getName() {
return name;
}
public int getBirthYear() {
return birthYear;
}
public void setName(String name) {
this.name = name;
}
public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Person person = (Person) obj;
return name.equals(person.name) && birthYear == person.birthYear;
}
public String toString() {
return String.format("Person: Name: %30s | Birth Year: %4d", name, birthYear);
}
public int compareTo(Person p) {
return Integer.compare(birthYear, p.birthYear);
}
}