Corretti i loop con eccezioni
This commit is contained in:
@@ -100,8 +100,9 @@ public class listaSpesa {
|
||||
System.out.print("Inserire la descrizione: ");
|
||||
descrizione = sc.nextLine();
|
||||
|
||||
try {
|
||||
do {
|
||||
do {
|
||||
try {
|
||||
|
||||
error = false;
|
||||
System.out.print("Inserire il prezzo: ");
|
||||
prezzo = sc.nextFloat();
|
||||
@@ -111,13 +112,15 @@ public class listaSpesa {
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: numero non valido.");
|
||||
}
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: numero non valido.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
try {
|
||||
do {
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
System.out.print("Inserire lo sconto con carta fedeltà (in %): ");
|
||||
scontoFidelityCard = sc.nextFloat() / 100;
|
||||
@@ -127,10 +130,11 @@ public class listaSpesa {
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: numero non valido.");
|
||||
}
|
||||
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: numero non valido.");
|
||||
}
|
||||
} while (error);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
@@ -165,8 +169,8 @@ public class listaSpesa {
|
||||
}
|
||||
} while (error);
|
||||
|
||||
try {
|
||||
do {
|
||||
do {
|
||||
try {
|
||||
error = false;
|
||||
System.out.print("Inserire la quantità: ");
|
||||
qta = isAlimentare ? sc.nextFloat() : (float) sc.nextInt();
|
||||
@@ -176,10 +180,11 @@ public class listaSpesa {
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: numero non valido.");
|
||||
}
|
||||
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Errore: numero non valido.");
|
||||
}
|
||||
} while (error);
|
||||
|
||||
magazzino[indiceMagazzino] = isAlimentare
|
||||
? new Alimentare(nome, prezzo, qta, scontoFidelityCard, dataScadenza, descrizione)
|
||||
@@ -351,7 +356,7 @@ public class listaSpesa {
|
||||
static int trovaPosizioneLibera(Prodotto[] p_prodotti) {
|
||||
int ritorno = -1;
|
||||
boolean exit = false;
|
||||
|
||||
|
||||
for (int i = 0; i < p_prodotti.length && !exit; i++) {
|
||||
if (p_prodotti[i] == null) {
|
||||
ritorno = i;
|
||||
|
||||
Reference in New Issue
Block a user