-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersona.java
70 lines (57 loc) · 1.58 KB
/
Persona.java
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
package prg.es2;
public class Persona{
private String nome = new String();
private String cognome = new String();
private int eta;
//COSTRUTTORI:
public Persona(){}
public Persona(String name, String surname, int eta){
this.setName(name);
this.setSurname(surname);
this.setEta(eta);
}
public Persona(String name, String surname){
this.setName(name);
this.setSurname(surname);
}
//METODI:
public Persona setName(String name){
this.nome = name;
return this;
}
public Persona setSurname(String surname){
this.cognome = surname;
return this;
}
public Persona setEta(int eta){
if(eta >= 0 && eta < 160){
this.eta = eta;
} else {
System.out.println("Errore. Eta' non valida");
}
return this;
}
public String getName(){
return this.nome;
}
public String getSurname(){
return this.cognome;
}
public int getEta(){
return this.eta;
}
public String toString(){
return "Nome: " + this.getName() + " Cognome: " + this.getSurname() + " Eta: " + this.getEta();
}
public void toPrint(){
//System.out.println(this.toString()); potrei implementare in questo modo. Tuttavia per ottenere un testo formattato preferisco:
System.out.printf("Nome: %-15s\tCognome: %-15s\tEta': %d\n", this.getName(), this.getSurname(), this.getEta());
}
public boolean equals(Persona soggetto){
if(this.getName().equalsIgnoreCase(soggetto.getName()) && this.getSurname().equalsIgnoreCase(soggetto.getSurname()) && this.getEta() == soggetto.getEta()){
return true;
} else {
return false;
}
}
}