Aggiunto GetPostiLiberi
This commit is contained in:
parent
a3bacfe016
commit
069a4f03b4
@ -101,7 +101,27 @@ public class Garage {
|
||||
}
|
||||
|
||||
public String GetPostiLiberi() {
|
||||
return "I posti liberi sono da %d a %d".formatted(--posizioneLibera, veicoli.length);
|
||||
String ritorno;
|
||||
boolean vuoto = true;
|
||||
int posti[] = TrovaPosti(false);
|
||||
|
||||
for (int i = 0; i < posti.length && vuoto; i++) {
|
||||
if (posti[i] != -1) {
|
||||
vuoto = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (vuoto) {
|
||||
ritorno = "Non c'è nessun posto libero.";
|
||||
} else {
|
||||
ritorno = "I posti liberi sono:\n";
|
||||
for (int posizione : posti) {
|
||||
if (posizione != -1) {
|
||||
ritorno += posizione + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
public String UscitaAuto() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user