Gestione garage pieno

This commit is contained in:
La Programmatrice Verde
2025-09-25 17:21:10 +02:00
parent 75319d7329
commit 6632a5535a
2 changed files with 10 additions and 4 deletions

View File

@@ -33,14 +33,20 @@ public class Garage {
public String IngressoAuto() {
Scanner sc = new Scanner(System.in);
String targa;
String targa, ritorno;
System.out.println("Inserire la targa dell'auto: ");
targa = sc.nextLine();
veicoli[this.NextPosizioneLibera()] = new Auto(targa);
try{
veicoli[this.NextPosizioneLibera()] = new Auto(targa);
ritorno = "L'auto è posteggiata nella posizione %d".formatted(posizioneLibera++);
}
catch(ArrayIndexOutOfBoundsException e){
ritorno = "Errore: il garage è pieno.";
}
return "L'auto è posteggiata nella posizione %d".formatted(posizioneLibera);
return ritorno;
}
public String GetPostiOccupati() {