-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContatto.java
More file actions
73 lines (59 loc) · 1.62 KB
/
Contatto.java
File metadata and controls
73 lines (59 loc) · 1.62 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
package prg.es2;
import java.lang.IllegalArgumentException;
import java.util.Objects;
public class Contatto implements Comparable<Contatto>{
private String name;
private String surname;
private long phone;
public Contatto(){}
public Contatto(String name, String surname, long phone){
this.setName(name).setSurname(surname).setPhone(phone);
}
//METODI SET
public Contatto setName(String name){
this.name = name;
return this;
}
public Contatto setSurname(String surname){
this.surname = surname;
return this;
}
public Contatto setPhone(long phone){
if(phone > 299_999_9999.00){
this.phone = phone;
} else {
throw new IllegalArgumentException();
}
return this;
}
//METODI GET
public String getName(){
return this.name;
}
public String getSurname(){
return this.surname;
}
public long getPhone(){
return this.phone;
}
public String toString(){
return this.getName() + "\t" + this.getSurname() + "\t" + this.getPhone() + "\t";
}
public boolean equals(Object other){
if(other instanceof Contatto){
Contatto sec = (Contatto) other;
return this.getName().equals(sec.getName()) && this.getSurname().equals(sec.getSurname()) && this.getPhone() == sec.getPhone();
}
return false;
}
public int hashCode(){
return Objects.hash(this.getName(), this.getSurname(), this.getPhone());
}
public int compareTo(Contatto other){
if(this.getSurname().equals(other.getSurname())){
return this.getName().compareTo(other.getName());
} else {
return this.getSurname().compareTo(other.getSurname());
}
}
}