Question:
I cant understand why this is happening
Repl link:
Ephraim mart test - Replit
int whichFood = 0;
int howMany = 0;
double basePrice = 0.0;
out.println("Which one do you want?");
out.println("(Please don't enter a typed out number like \"one\", enter a numeric one like\"1\"");
for (int i = 0; i < martFruit.length; i++) {
out.println((i + 1) + ") " + martFruit[i].get("name") + " - " + martFruit[i].get("price"));
// prints list of fruit and their prices
}
while (whichFood == 0) {
whichFood = 0;
try {
whichFood = input.nextInt();
out.println("OK!");
out.println("How many do you want? (limit - 100)");
out.println("(Please don't enter a typed out number like \"one\", enter a numeric one like\"1\"");
while (howMany == 0) {
howMany = 0;
try {
howMany = input.nextInt();
if (howMany > 0 && howMany < 101) {
out.println("OK! " + howMany + " it is!");
} else {
out.println("Really?");
out.println("Try again.");
out.println("A");
howMany = 0;
}
// if else works
} catch (Exception e) {
out.println("Really?");
out.println("Try again.");
out.println("B");
howMany = 0;
}
}
} catch (Exception e) {
out.println("Really?");
out.println("Try again.");
out.println("C");
whichFood = 0;
}
}
(the varible martFruit is an arraylist and is not causing the error)
any help would be great!
the lettersin the else statements and the catch statements are so I knov which one is the code repeating