From 9f495c908f088bfdc33483956b4ff11271a31a9e Mon Sep 17 00:00:00 2001 From: La Programmatrice Verde Date: Tue, 28 Oct 2025 12:33:58 +0100 Subject: [PATCH] Miglioria UX --- src/garage/MainGarage.java | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/garage/MainGarage.java b/src/garage/MainGarage.java index de6f598..b5ae9e2 100644 --- a/src/garage/MainGarage.java +++ b/src/garage/MainGarage.java @@ -233,34 +233,31 @@ public class MainGarage { int posizione = 0; VeicoloAMotore veicoloEstratto = null; + error = false; + do { - error = false; + try { + System.out.print("Inserire la posizione: "); + posizione = sc.nextInt(); - do { - try { - System.out.print("Inserire la posizione: "); - posizione = sc.nextInt(); - - if (posizione <= 0 || posizione >= Garage.DIMENSIONE_GARAGE) { - System.out.println("Errore: la posizione non esiste."); - pausa(); - error = true; - } - } catch (InputMismatchException _) { - System.out.println("Errore nella lettura della posizione."); + if (posizione <= 0 || posizione >= Garage.DIMENSIONE_GARAGE) { + System.out.println("Errore: la posizione non esiste."); pausa(); error = true; } - } while (error); - - veicoloEstratto = garage.estraiVeicolo(posizione); - if (veicoloEstratto != null) { - System.out.println(veicoloEstratto.toString()); - } else { - System.out.println("Errore: la posizione indicata è vuota."); + } catch (InputMismatchException _) { + System.out.println("Errore nella lettura della posizione."); pausa(); error = true; } } while (error); + + veicoloEstratto = garage.estraiVeicolo(posizione); + if (veicoloEstratto != null) { + System.out.println("Veicolo estratto:"); + System.out.println(veicoloEstratto.toString()); + } else { + System.out.println("Errore: la posizione indicata è vuota."); + } } }