-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainUpgrade1.java
94 lines (84 loc) · 2.83 KB
/
MainUpgrade1.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
/*
*
* made by:
* Confalonieri Riccardo
* github.com/rconfa
*
*/
package carParks;
import java.util.Scanner;
public class MainUpgrade1 {
public static void main(String[] args) {
Scanner tastiera = new Scanner(System.in);
/*
* RICHIESTA DEI DATI ALL'UTENTE - per semplicità e velocità di testing abbiamo
* deciso dare dei valori di default. Per avere una targa univoca prendiamo i
* millisecondi attuali.
*
* String nome = tastiera.next(); String cognome = tastiera.next(); String cf =
* tastiera.next(); String targa = tastiera.next(); String marca =
* tastiera.next(); String modello = tastiera.next(); int cilindrata =
* tastiera.nextInt(); Automobile auto1 = new Automobile(targa, marca, modello,
* cilindrata); Automobilista a1 = new Automobilista(nome, cognome, cf, auto1);
*/
Automobile auto1 = new Automobile("" + System.currentTimeMillis(), "Fiat", "Punto", 1000);
Automobilista a1 = new Automobilista("Name", "Surname", "Cf", auto1);
int scelta;
String response = "";
boolean errorChiusura = false;
do {
System.out.println("\nCiao, cosa vuoi fare? Scegli il numero: ");
System.out.println("1) Stampa i parcheggi disponibili ");
System.out.println("2) Scegli un parcheggio (numero) ");
System.out.println("3) Parcheggia ");
System.out.println("4) Ritira ");
System.out.println("5) Chiudi ");
scelta = tastiera.nextInt();
response = "";
errorChiusura = false;
switch (scelta) {
case 1:
response = a1.richiediParcheggiDisponibili();
printParcheggi(response);
break;
case 2:
System.out.println("Inserisci il numero del parcheggio voluto: ");
int numParcheggio = tastiera.nextInt();
response = a1.selezionaParcheggio(numParcheggio);
System.out.println(response);
break;
case 3:
response = a1.parcheggiaConServer();
System.out.println(response);
break;
case 4:
response = a1.ritiraConServer();
System.out.println(response);
break;
case 5:
response = a1.chiudiConnessione();
if (response.equals("errorParcheggiato")) {
System.out.println("Hai parcheggiato, ritira la macchina prima di chiudere la connessione!");
errorChiusura = true;
} else
System.out.println(response);
break;
default:
System.out.println("input non riconosciuto");
break;
}
} while (scelta != 5 || errorChiusura);
tastiera.close();
}
private static void printParcheggi(String response) {
if (response.contains(";")) {
String[] parcheggiDispo = response.split(";");
for (int i = 0; i < parcheggiDispo.length; i++) {
if (parcheggiDispo[i].equals("") == false)
System.out.println((i + 1) + ") " + parcheggiDispo[i]);
}
} else
System.out.println(response);
}
}