-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rubrica.java
105 lines (94 loc) · 2.56 KB
/
Rubrica.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package prg.es2;
import java.util.TreeSet;
import java.util.Scanner;
public class Rubrica{
Scanner input = new Scanner(System.in);
TreeSet<Contatto> elenco;
public Rubrica(){
elenco = new TreeSet<>();
}
private Contatto addContact(Contatto newPerson){
System.out.print("Inserisci Nome: ");
newPerson.setName(input.nextLine());
System.out.print("Inserisci Cognome: ");
newPerson.setSurname(input.nextLine());
System.out.print("Inserisci numero: ");
newPerson.setPhone(input.nextLong());
input = new Scanner(System.in);
return newPerson;
}
public Rubrica addFriend(){
System.out.println("INSERMIMENTO AMICO");
Friend newFriend = new Friend();
newFriend = (Friend) this.addContact(newFriend);
System.out.print("Inserisci indirizzo: ");
newFriend.setAddress(input.nextLine());
elenco.add(newFriend);
return this;
}
public Rubrica addCollega(){
System.out.println("INSERMIMENTO COLLEGA");
Collega newCollega = new Collega();
newCollega = (Collega) this.addContact(newCollega);
System.out.print("Inserisci qualifica: ");
newCollega.setQualifica(input.nextLine());
elenco.add(newCollega);
return this;
}
public Rubrica printFriends(){
System.out.println("CONTATTI DI AMICI: ");
boolean check = false;
for(Contatto id : elenco){
if(id instanceof Friend){
System.out.println(id);
check = true;
}
}
if(check == false){
System.out.println("Nessun contatto di amici presente");
}
return this;
}
public Rubrica printColleghi(){
System.out.println("CONTATTI DI COLLEGHI: ");
boolean check = false;
for(Contatto id : elenco){
if(id instanceof Collega){
System.out.println(id);
check = true;
}
}
if(check == false){
System.out.println("Nessun contatto di colleghi presente");
}
return this;
}
public Rubrica toPrint(){
System.out.println("TUTTI I CONTATTI: ");
if(elenco.isEmpty()){
System.out.println("Nessun contatto memorizzato");
}
for(Contatto id : elenco){
System.out.println(id);
}
return this;
}
public Rubrica clear(){
elenco.clear();
System.out.println("Rubrica cancellata");
return this;
}
public Contatto search(){
System.out.print("Inserisci nome: ");
String name = input.next();
System.out.print("Inserisci cognome: ");
String surname = input.next();
for(Contatto id : elenco){
if(id.getName().equals(name) && id.getSurname().equals(surname)){
return id;
}
}
System.out.println("Nessun contatto trovato!");
return null;
}
}