Question: ss 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.
ss
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 1-8. 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: 1. Throws an InputMismatchException. 2. Outputs "Fatal error". 3. Exits the while loop. If the user enters an integer that is out of range, then the program: 1. Throws an Exception. 2. Outputs the exception message "Number out of range. Try again." and continues to execute the while loop. Click here for example v How to use this tool Unused VendingMachine.java Load default template... System. out. print In (excpt. getMessage ( ) ) ; public class VendingMachine { public static void main (String args) { Scanner scnr = new Scanner (System. in) ; catch (Exception excpt) { int itemNumber = 0; boolean askForInput = true; System. out . print In("Fatal error"); while (askForInput) { try { catch (InputMismatchException excpt) { itemNumber = scnr. nextInt ( ) ; askForInput = false; if ((itemNumber 8) ) { throw new Exception ( "Number out of range. Try again.") System. out. print In("Dispensing item: " + itemNumber); askForInput = falseStep 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
