Attachment 'Ristorante.java'
Download 1 import java.util.ArrayList;
2
3 public class Ristorante {
4
5 ArrayList<Prenotazione> prenotati=new ArrayList<Prenotazione>();
6
7 public void aggiungiPrenotazione(String cognome, int numeroPersone)
8 {
9 prenotati.add(new Prenotazione(cognome, numeroPersone));
10 }
11
12 public ArrayList<Prenotazione> cercaUnaPrenotazione(String cognome)
13 {
14 ArrayList<Prenotazione> temp=new ArrayList<Prenotazione>();
15
16 for(Prenotazione p:prenotati)
17 {
18 if(p.getCognome().equals(cognome))
19 temp.add(p);
20 }
21
22 return temp;
23
24 }
25
26 public void cancellaPrenotazione(String cognome)
27 {
28 ArrayList<Prenotazione> temp=cercaUnaPrenotazione(cognome);
29
30 for(Prenotazione p: temp)
31 prenotati.remove(p);
32 }
33
34 public static void main(String[] args) {
35 Ristorante r=new Ristorante();
36
37 r.aggiungiPrenotazione("Sirianni", 4);
38
39 for(Prenotazione p:r.prenotati)
40 {
41 System.out.println(p.getCognome());
42 }
43
44 r.cancellaPrenotazione("Sirianni");
45
46 for(Prenotazione p:r.prenotati)
47 {
48 System.out.println(p.getCognome());
49 }
50 }
51 }
Attached Files
You are not allowed to attach a file to this page.