Question: The following program simulates a vending machine panel. The program reads an integer representing the user's selected item, and then outputs a dispensing message. The
The following program simulates a vending machine panel. The program reads an integer representing the user's selected item, and then outputs a dispensing message. The vending machine accepts integers in the range Organize the lines of code to throw and handle two exceptions.
If the user enters a value that is not an integer, then the program:
Throws an InputMismatchException.
Outputs "Fatal error".
Exits the while loop.
If the user enters an integer that is out of range, then the program:
Throws an Exception.
Outputs the exception message "Number out of range. Try again." and continues to execute the while loop.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
