Inizio metodi PostiOccupati e Liberi

This commit is contained in:
La Programmatrice Verde 2025-09-25 11:48:28 +02:00
parent e8f8461679
commit 72cce911ed
2 changed files with 14 additions and 7 deletions

View File

@ -33,6 +33,7 @@ public class EsercizioGarage {
System.out.print("Opzione: ");
scelta = sc.nextInt();
sc.nextLine();
switch (scelta) {
case 0:
@ -64,6 +65,6 @@ public class EsercizioGarage {
public static void Pausa() {
System.out.println("Premere un tasto per continuare. . .");
sc.next();
sc.nextLine();
}
}

View File

@ -19,18 +19,24 @@ public class Garage {
this.veicoli = new Auto[p_dimensione];
}
public void IngressoAuto(){
public String IngressoAuto() {
Scanner sc = new Scanner(System.in);
String targa;
System.out.println("Inserire la targa dell'auto: ");
targa = sc.next();
targa = sc.nextLine();
veicoli[this.posizioneLibera++] = new Auto(targa);
System.out.println("L'auto è posteggiata nella posizione %d".formatted(posizioneLibera));
return "L'auto è posteggiata nella posizione %d".formatted(posizioneLibera);
}
public String GetPostiOccupati() {
return "I posti occupati sono da 0 a %d".formatted(--posizioneLibera);
}
public String GetPostiLiberi() {
return "I posti liberi sono da %d a %d".formatted(--posizioneLibera, veicoli.length);
}
GetPostiOccupati();
GetPostiLiberi();
UscitaAuto();
}