Could you please help me with this question? Thank you.
PARTICIPATION ACTIVITY
6.2.6: Handling multiple exceptions: vending machine example
The following program simulates a vending machine panel. The program gets an integer that represents the user's selected item.
integer input, the program throws an InputMismatchException, outputs "Fatal error", and then exits.
Not all lines are used in the solution.
How to use this tool:
Unused
VendingMachine.java
Load default template.
askForInput = true;
askForInput = false;
import java.util.Scanner;
import java.util.InputMismatchException;
System.out.println("Fatal error");
public class VendingMachine {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int itemNumber = 0;
boolean askForInput = true;
System.out.println(excpt);
catch (Exception excpt) {
System.out.println(excpt.toString());
System.out.println(excpt.getMessage())
}
while (askForInput) {
try {
itemNumber = scnr.nextInt;
if (itemNumber <= 0 || itemNumber > 8) {
throw new Exception("Try again");
}
}
catch (InputMismatchException excpt) {
System.out.println("Dispensing item " + itemNumbe);
askForInput = false;
}
}
}
}
Check
Feedback?