Aggiunto GetPostiLiberi

This commit is contained in:
La Programmatrice Verde 2025-09-25 22:32:29 +02:00
parent a3bacfe016
commit 069a4f03b4

View File

@ -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() {