Gestione garage pieno
This commit is contained in:
@@ -19,7 +19,7 @@ public class EsercizioGarage {
|
|||||||
static Scanner sc = new Scanner(System.in);
|
static Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int DIMENSIONE_GARAGE = 5;
|
int DIMENSIONE_GARAGE = 3;
|
||||||
Garage garage = new Garage(DIMENSIONE_GARAGE);
|
Garage garage = new Garage(DIMENSIONE_GARAGE);
|
||||||
int scelta;
|
int scelta;
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,20 @@ public class Garage {
|
|||||||
|
|
||||||
public String IngressoAuto() {
|
public String IngressoAuto() {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
String targa;
|
String targa, ritorno;
|
||||||
|
|
||||||
System.out.println("Inserire la targa dell'auto: ");
|
System.out.println("Inserire la targa dell'auto: ");
|
||||||
targa = sc.nextLine();
|
targa = sc.nextLine();
|
||||||
|
|
||||||
|
try{
|
||||||
veicoli[this.NextPosizioneLibera()] = new Auto(targa);
|
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() {
|
public String GetPostiOccupati() {
|
||||||
|
|||||||
Reference in New Issue
Block a user