Question: The following program simulates a vending machine panel. The program gets an integer that represents the user's selected item, and then outputs a dispensing message.

The following program simulates a vending machine panel. The program gets an integer that represents the user's selected item, and then outputs a dispensing message. Only 8 items are for purchase. Ex. The input 2 results in the message "Dispensing item 2n.
Arrange the following lines to handle two exceptions. If the user enters an item number that is not for purchase, the program throws an Exception with the message "Try again", outputs the exception message, and then tries again. If the user enters a noninteger 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
askForInput ?3 true;
askForInput = false;
System, out.println("Fatal error");
System.out.println(excpt);
}
System.out.println(excpt.getMessage());
System.out.println (excpt.tostring());
catch (InputMismatchException excpt){
}
catch (Exception excpt){
VendingMachine.java
Load default template...
import java.util.Scanner;
import java.util.InputMismatchException;
public class VendingMachine {
public static void main (String [] args) f
Scanner scnr= new Scanner
System.in);
int itemNumber =0;
boolean askForInput = true;
while (askForInput){
try {
itemNumber =scnr* nextInt ();
if itemNumber 0 itemNumber >8)
throw new Exception("Try again");
System.out.println("Dispensing item "+ iter
 The following program simulates a vending machine panel. The program gets

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!