Controllo età + rimoszione controllo eccezione inutile
This commit is contained in:
parent
33a4618a18
commit
8221c2e0f3
@ -164,7 +164,7 @@ public class ereditarieta {
|
||||
String nome;
|
||||
String cognome;
|
||||
String sesso;
|
||||
String età;
|
||||
String età = "";
|
||||
String professione;
|
||||
String classe;
|
||||
String indirizzoDiStudio;
|
||||
@ -210,8 +210,25 @@ public class ereditarieta {
|
||||
System.out.print("Inserire il sesso: ");
|
||||
sesso = sc.nextLine();
|
||||
|
||||
System.out.print("Inserire l'età: ");
|
||||
età = sc.nextLine();
|
||||
do {
|
||||
error = true;
|
||||
int etàInt;
|
||||
System.out.print("Inserire l'età: ");
|
||||
try {
|
||||
etàInt = sc.nextInt();
|
||||
sc.nextLine();
|
||||
if (etàInt <= 0) {
|
||||
System.out.println("Errore: l'età deve essere maggiore di 0.");
|
||||
pausa();
|
||||
} else {
|
||||
error = false;
|
||||
età = String.valueOf(etàInt);
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: età non valida.");
|
||||
pausa();
|
||||
}
|
||||
} while (error);
|
||||
|
||||
do {
|
||||
error = true;
|
||||
@ -223,54 +240,49 @@ public class ereditarieta {
|
||||
System.out.print("Inserire la professione: ");
|
||||
professione = sc.nextLine().toLowerCase();
|
||||
|
||||
try {
|
||||
switch (professione) {
|
||||
case "nessuna":
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Persona(nome, cognome, sesso, età);
|
||||
error = false;
|
||||
System.out.println("Persona inserita con successo.");
|
||||
break;
|
||||
case "studente":
|
||||
System.out.print("Inserire la classe: ");
|
||||
classe = sc.nextLine();
|
||||
switch (professione) {
|
||||
case "nessuna":
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Persona(nome, cognome, sesso, età);
|
||||
error = false;
|
||||
System.out.println("Persona inserita con successo.");
|
||||
break;
|
||||
case "studente":
|
||||
System.out.print("Inserire la classe: ");
|
||||
classe = sc.nextLine();
|
||||
|
||||
System.out.print("Inserire l'indirizzo di studio: ");
|
||||
indirizzoDiStudio = sc.nextLine();
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Studente(nome, cognome, sesso, età,
|
||||
classe, indirizzoDiStudio);
|
||||
error = false;
|
||||
System.out.println("Studente inserito con successo.");
|
||||
break;
|
||||
case "calciatore":
|
||||
System.out.print("Inserire la squadra: ");
|
||||
squadra = sc.nextLine();
|
||||
System.out.print("Inserire l'indirizzo di studio: ");
|
||||
indirizzoDiStudio = sc.nextLine();
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Studente(nome, cognome, sesso, età,
|
||||
classe, indirizzoDiStudio);
|
||||
error = false;
|
||||
System.out.println("Studente inserito con successo.");
|
||||
break;
|
||||
case "calciatore":
|
||||
System.out.print("Inserire la squadra: ");
|
||||
squadra = sc.nextLine();
|
||||
|
||||
System.out.print("Inserire il numero di maglia: ");
|
||||
numeroMaglia = sc.nextLine();
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Calciatore(nome, cognome, sesso, età,
|
||||
squadra, numeroMaglia);
|
||||
error = false;
|
||||
System.out.println("Calciatore inserito con successo.");
|
||||
break;
|
||||
case "influencer":
|
||||
System.out.print("Inserire il numero di follower: ");
|
||||
numeroFollower = sc.nextLine();
|
||||
System.out.print("Inserire il numero di maglia: ");
|
||||
numeroMaglia = sc.nextLine();
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Calciatore(nome, cognome, sesso, età,
|
||||
squadra, numeroMaglia);
|
||||
error = false;
|
||||
System.out.println("Calciatore inserito con successo.");
|
||||
break;
|
||||
case "influencer":
|
||||
System.out.print("Inserire il numero di follower: ");
|
||||
numeroFollower = sc.nextLine();
|
||||
|
||||
System.out.print("Inserire l'handle: ");
|
||||
handle = sc.nextLine();
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Influencer(nome, cognome, sesso, età,
|
||||
numeroFollower, handle);
|
||||
error = false;
|
||||
System.out.println("Influencer inserito con successo.");
|
||||
break;
|
||||
default:
|
||||
System.out.println("Opzione non valida.");
|
||||
pausa();
|
||||
break;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
System.out.print("Inserire l'handle: ");
|
||||
handle = sc.nextLine();
|
||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Influencer(nome, cognome, sesso, età,
|
||||
numeroFollower, handle);
|
||||
error = false;
|
||||
System.out.println("Influencer inserito con successo.");
|
||||
break;
|
||||
default:
|
||||
System.out.println("Opzione non valida.");
|
||||
pausa();
|
||||
break;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user