Creazione metodo IngressoAuto
This commit is contained in:
@@ -15,24 +15,26 @@ public class EsercizioGarage {
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static void main(String[] args) {
|
||||
int DIMENSIONE_GARAGE = 5;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
Garage garage = new Garage(DIMENSIONE_GARAGE);
|
||||
int scelta;
|
||||
|
||||
do{
|
||||
|
||||
do {
|
||||
System.out.println("Scegliere un'opzione:");
|
||||
System.out.println("1. Ingresso auto");
|
||||
System.out.println("2. Stampa posti occupati");
|
||||
System.out.println("3. Stampa posti liberi");
|
||||
System.out.println("3. Stampa posti liberi");
|
||||
System.out.println("4. Uscita auto");
|
||||
System.out.println("0. Esci");
|
||||
System.out.print("Opzione: ");
|
||||
|
||||
|
||||
scelta = sc.nextInt();
|
||||
|
||||
switch (scelta){
|
||||
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
@@ -55,14 +57,12 @@ public class EsercizioGarage {
|
||||
System.out.println("Opzione non valida.");
|
||||
Pausa();
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
while (scelta != 0);
|
||||
} while (scelta != 0);
|
||||
}
|
||||
|
||||
public static void Pausa(){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static void Pausa() {
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
sc.next();
|
||||
}
|
||||
|
||||
@@ -4,14 +4,33 @@
|
||||
*/
|
||||
package eserciziogarage;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
*/
|
||||
public class Garage {
|
||||
Auto[] veicoli;
|
||||
|
||||
private int posizioneLibera = 0;
|
||||
|
||||
public Garage(int p_dimensione){
|
||||
this.veicoli = new Auto[p_dimensione];
|
||||
}
|
||||
|
||||
public void IngressoAuto(){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String targa;
|
||||
|
||||
System.out.println("Inserire la targa dell'auto: ");
|
||||
targa = sc.next();
|
||||
|
||||
veicoli[this.posizioneLibera++] = new Auto(targa);
|
||||
|
||||
System.out.println("L'auto è posteggiata nella posizione %d".formatted(posizioneLibera));
|
||||
}
|
||||
GetPostiOccupati();
|
||||
GetPostiLiberi();
|
||||
UscitaAuto();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user