-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRubrica.java
More file actions
75 lines (66 loc) · 2.05 KB
/
Rubrica.java
File metadata and controls
75 lines (66 loc) · 2.05 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
74
75
package prg.es4;
import prg.es2.Persona;
import java.util.ArrayList;
import java.util.Scanner;
public class Rubrica{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Persona> miaLista = new ArrayList<>();
String key = new String();
label:
while(key != "e"){
System.out.println("MENU:");
System.out.println("a. Inserisci nuovo utente");
System.out.println("b. Cerca persona");
System.out.println("c. Mostra lista");
System.out.println("d. Cancella tutta la lista");
System.out.println("e. Esci");
switch (key = input.next()) {
case "a": //AGGIUNGI PERSONA
Persona p1 = new Persona();
System.out.print("Inserisci nome persona: ");
p1.nome = input.next();
System.out.print("Inserisci cognome persona: ");
p1.cognome = input.next();
System.out.print("Inserisci eta persona: ");
p1.eta = input.nextInt();
miaLista.add(p1);
System.out.println();
break;
case "b": //CERCA PER NOME
System.out.println("Inserisci nome:");
String a = input.next();
boolean state = false;
for(Persona tmp : miaLista){
if(tmp.nome.equals(a)){
state = true;
System.out.println(tmp.nome + " " + tmp.cognome + " " + tmp.eta);
}
}
if(state == false){
System.out.println("Non e' presente alcuna persona con il nome " + a + " nella lista");
}
System.out.println();
break;
case "c": //MOSTRA INTERA LISTA
for(Persona tmp : miaLista){
System.out.printf("%s\t%s\t%d\n", tmp.nome, tmp.cognome, tmp.eta);
}
System.out.println();
break;
case "d": //CANCELLA LISTA
miaLista.clear();
System.out.println("Lista cancellata.");
System.out.println();
break;
case "e": //TERMINA PROGRAMMA
break label;
default:
System.out.println("OPZIONE NON VALIDA. Inserire 'a', 'b', 'c', 'd' o 'e'");
System.out.println();
break;
}
}
System.out.println("FINE PROGRAMMA!");
}
}