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 nome;
|
||||||
String cognome;
|
String cognome;
|
||||||
String sesso;
|
String sesso;
|
||||||
String età;
|
String età = "";
|
||||||
String professione;
|
String professione;
|
||||||
String classe;
|
String classe;
|
||||||
String indirizzoDiStudio;
|
String indirizzoDiStudio;
|
||||||
@ -210,8 +210,25 @@ public class ereditarieta {
|
|||||||
System.out.print("Inserire il sesso: ");
|
System.out.print("Inserire il sesso: ");
|
||||||
sesso = sc.nextLine();
|
sesso = sc.nextLine();
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = true;
|
||||||
|
int etàInt;
|
||||||
System.out.print("Inserire l'età: ");
|
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 {
|
do {
|
||||||
error = true;
|
error = true;
|
||||||
@ -223,7 +240,6 @@ public class ereditarieta {
|
|||||||
System.out.print("Inserire la professione: ");
|
System.out.print("Inserire la professione: ");
|
||||||
professione = sc.nextLine().toLowerCase();
|
professione = sc.nextLine().toLowerCase();
|
||||||
|
|
||||||
try {
|
|
||||||
switch (professione) {
|
switch (professione) {
|
||||||
case "nessuna":
|
case "nessuna":
|
||||||
ritorno[arrayNuovo ? i : p_persone.length + i] = new Persona(nome, cognome, sesso, età);
|
ritorno[arrayNuovo ? i : p_persone.length + i] = new Persona(nome, cognome, sesso, età);
|
||||||
@ -268,10 +284,6 @@ public class ereditarieta {
|
|||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (InputMismatchException e) {
|
|
||||||
System.out.println("Errore: scelta non valida.");
|
|
||||||
pausa();
|
|
||||||
}
|
|
||||||
} while (error);
|
} while (error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user