Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed 

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 2. 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 non- integer input, the program throws an InputMismatchException, outputs "Fatal error", and then exits. Not all lines are used in the solution. Mouse: Drag/drop Keyboard: Grab/release Spacebar (or Enter). Move 1000. Cancel Esc Unused catch (Exception excpt) { askForInput = true; askForInput = false; } System.out.println("Fatal error"); System.out.println (excpt); catch (InputMismatchException excpt) { } System.out.println(excpt.toString()); System.out.println(excpt.getMessage()); Vending Machine.java import java.util.Scanner; import java.util. InputMismatchException; public class Vending Machine { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int itemNumber = 0; boolean askFor Input = true; Load default template... while (askForInput) { try { itemNumber = scnr.nextInt (); if ((itemNumber 8)) { throw new Exception ("Try again"); } System.out.println("Dispensing item askFor Input = false; I + itemNumbe

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javautilScanner import javautilInputMismatch... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions

Question

What is the AIDA model, and what are its limitations?

Answered: 1 week ago