-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
52 lines (45 loc) · 909 Bytes
/
Copy pathPerson.java
File metadata and controls
52 lines (45 loc) · 909 Bytes
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
package cCollections;
import java.util.Objects;
public class Person implements Comparable<Person> {
public String name;
protected int age;
public Person(){
this.name = "unnamed";
this.age = -1;
}
public Person(String name){
this.name = name;
this.age = -1;
}
public Person(String name, int age){
this.name = name;
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String hello(){
return "hello, I am " + name;
}
@Override
public boolean equals(Object obj){
if (obj == this){
return true;
}
if (obj instanceof Person){
Person p = (Person) obj;
return Objects.equals(this.name, p.name) && this.age == p.age;
}
return false;
}
public int hashCode(){
return Objects.hash(this.name, this.age);
}
@Override
public int compareTo(Person o) {
return this.name.compareTo(o.name);
}
}