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

@@ -19,7 +19,7 @@ public class EsercizioGarage {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int DIMENSIONE_GARAGE = 5;
int DIMENSIONE_GARAGE = 3;
Garage garage = new Garage(DIMENSIONE_GARAGE);
int scelta;

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