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();
|
||||
|
||||
do {
|
||||
error = true;
|
||||
int etàInt;
|
||||
System.out.print("Inserire l'età: ");
|
||||
età = sc.nextLine();
|
||||
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,7 +240,6 @@ 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à);
|
||||
@ -268,10 +284,6 @@ public class ereditarieta {
|
||||
pausa();
|
||||
break;
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: scelta non valida.");
|
||||
pausa();
|
||||
}
|
||||
} while (error);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user