Opzione 1
This commit is contained in:
@@ -18,15 +18,20 @@ public class eventiTriennale {
|
||||
*/
|
||||
|
||||
static Scanner sc = new Scanner(System.in);
|
||||
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
||||
|
||||
public static void main(String[] args) {
|
||||
Evento[] eventi = null;
|
||||
String sceltaSiNo;
|
||||
boolean error;
|
||||
int scelta = -1;
|
||||
|
||||
do {
|
||||
System.out.println("Scegliere un'opzione:");
|
||||
System.out.println("1. ");
|
||||
System.out.println("2. ");
|
||||
System.out.println("3. ");
|
||||
System.out.println("1. Salva eventi");
|
||||
System.out.println("2. Mostra eventi");
|
||||
System.out.println("3. Mostra concerti musica classica");
|
||||
System.out.println("4. Sconto 5% mostre");
|
||||
System.out.println("0. Esci");
|
||||
System.out.print("Opzione: ");
|
||||
|
||||
@@ -38,7 +43,27 @@ public class eventiTriennale {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if (eventi != null) {
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Attenzione: esiste già una lista di eventi. Sovrascriverla? [S/N]");
|
||||
sceltaSiNo = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (sceltaSiNo) {
|
||||
case "s":
|
||||
eventi = inserisciEventi();
|
||||
break;
|
||||
case "n":
|
||||
System.out.println("La lista non è stata modificata.");
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} else {
|
||||
eventi = inserisciEventi();
|
||||
}
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
@@ -47,16 +72,19 @@ public class eventiTriennale {
|
||||
break;
|
||||
case 3:
|
||||
|
||||
pausa();
|
||||
break;
|
||||
case 4:
|
||||
|
||||
pausa();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Opzione non valida.");
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (InputMismatchException _) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
} catch (InputMismatchException _) {
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
}
|
||||
} while (scelta != 0);
|
||||
@@ -66,4 +94,181 @@ public class eventiTriennale {
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
sc.nextLine();
|
||||
}
|
||||
|
||||
static Evento[] inserisciEventi() {
|
||||
int numeroEventi = dimensione("della lista degli eventi");
|
||||
Evento[] eventi = new Evento[numeroEventi];
|
||||
boolean error;
|
||||
int scelta = -1;
|
||||
|
||||
for (int i = 0; i < numeroEventi; i++) {
|
||||
do {
|
||||
error = false;
|
||||
System.out.println("Di che tipo è l'evento numero " + (i + 1) + "? ");
|
||||
System.out.println("1. Mostra");
|
||||
System.out.println("2. Concerto");
|
||||
System.out.println("3. Incontro culturale");
|
||||
System.out.print("Scelta: ");
|
||||
try {
|
||||
scelta = sc.nextInt();
|
||||
|
||||
switch (scelta) {
|
||||
case 1:
|
||||
eventi[i] = mostra();
|
||||
break;
|
||||
case 2:
|
||||
eventi[i] = concerto();
|
||||
break;
|
||||
case 3:
|
||||
eventi[i] = incontroCulturale();
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException _) {
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
|
||||
} while (error);
|
||||
}
|
||||
|
||||
return eventi;
|
||||
}
|
||||
|
||||
static int dimensione(String diCheCosa) {
|
||||
int dimensione = 0;
|
||||
boolean error;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("inserire la dimensione " + diCheCosa + ": ");
|
||||
try {
|
||||
dimensione = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
||||
if (dimensione <= 0) {
|
||||
System.out.println("Errore: la quantità non può essere minore o uguale a zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException _) {
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
return dimensione;
|
||||
}
|
||||
|
||||
static Mostra mostra() {
|
||||
String titolo;
|
||||
float prezzo;
|
||||
String nome_artista;
|
||||
String[] sale;
|
||||
|
||||
System.out.print("Titolo della mostra: ");
|
||||
titolo = sc.nextLine().trim();
|
||||
|
||||
prezzo = prezzo();
|
||||
|
||||
System.out.print("Nome artista: ");
|
||||
nome_artista = sc.nextLine().trim();
|
||||
|
||||
sale = sale();
|
||||
|
||||
return new Mostra(titolo, prezzo, nome_artista, sale);
|
||||
}
|
||||
|
||||
static float prezzo() {
|
||||
float prezzo = 0;
|
||||
boolean error;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("Inserire il prezzo: ");
|
||||
try {
|
||||
prezzo = sc.nextFloat();
|
||||
sc.nextLine();
|
||||
|
||||
if (prezzo <= 0) {
|
||||
System.out.println("Errore: il prezzo non può essere minore o uguale a zero.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} catch (InputMismatchException _) {
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
return prezzo;
|
||||
}
|
||||
|
||||
static String[] sale() {
|
||||
int dimensione = dimensione("della lista delle sale");
|
||||
String[] sale = new String[dimensione];
|
||||
|
||||
for (int i = 0; i < sale.length; i++) {
|
||||
System.out.println("Inserire il nome della sala n. " + (i + 1) + ": ");
|
||||
sale[i] = sc.nextLine().trim();
|
||||
}
|
||||
|
||||
return sale;
|
||||
}
|
||||
|
||||
static Concerto concerto() {
|
||||
String titolo;
|
||||
float prezzo;
|
||||
String tipologia_musica;
|
||||
String nome;
|
||||
|
||||
System.out.print("Titolo della mostra: ");
|
||||
titolo = sc.nextLine().trim();
|
||||
|
||||
prezzo = prezzo();
|
||||
|
||||
System.out.print("Tipologia musica: ");
|
||||
tipologia_musica = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
System.out.print("Nome del performer: ");
|
||||
nome = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
return new Concerto(titolo, prezzo, tipologia_musica, nome);
|
||||
}
|
||||
|
||||
static IncontroCulturale incontroCulturale() {
|
||||
String titolo;
|
||||
float prezzo;
|
||||
String tema;
|
||||
String[] relatori;
|
||||
|
||||
System.out.print("Titolo della mostra: ");
|
||||
titolo = sc.nextLine().trim();
|
||||
|
||||
prezzo = prezzo();
|
||||
|
||||
System.out.print("Tema dell'incontro: ");
|
||||
tema = sc.nextLine().trim();
|
||||
|
||||
relatori = relatori();
|
||||
|
||||
return new IncontroCulturale(titolo, prezzo, tema, relatori);
|
||||
}
|
||||
|
||||
static String[] relatori() {
|
||||
int dimensione = dimensione("della lista dei relatori");
|
||||
String[] relatori = new String[dimensione];
|
||||
|
||||
for (int i = 0; i < relatori.length; i++) {
|
||||
System.out.println("Inserire il nome della/del relatrice/relatore n. " + (i + 1) + ": ");
|
||||
relatori[i] = sc.nextLine().trim();
|
||||
}
|
||||
|
||||
return relatori;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user