VendingMachine.java Load default template... public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int itemNumber = 0; boolean askForInput = true; while (askForInput) { try...


VendingMachine.java<br>Load default template...<br>public static void main (String [] args) {<br>Scanner scnr = new Scanner(System.in);<br>int itemNumber = 0;<br>boolean askForInput = true;<br>while (askForInput) {<br>try {<br>itemNumber = scnr.nextInt();<br>if ((itemNumber <= 0) || (itemNumber > 8)) {<br>throw new Exception(

Extracted text: VendingMachine.java Load default template... public static void main (String [] args) { 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 " + itemNumbe askForInput = false; } }
The following program simulates a vending machine panel. The program gets an integer that represents the user's selected item,<br>and then outputs a dispensing message. Only 8 items are for purchase. Ex: The input 2 results in the message
8)) { throw new Exception("Try again"); } catch (Exception excpt) { System.out.println("Dispensing item " askForInput = false; + itemNumbe "/>
Extracted text: 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 t++→. Cancel Esc Unused VendingMachine.java Load default template... catch (InputMismatchException excpt) { import java.util.Scanner; import java.util.InputMismatchException; System.out.println(excpt.toString()); System.out.println(excpt.getMessage ()); public class VendingMachine { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int itemNumber = 0; System.out.println(excpt); boolean askForInput = true; System.out.println("Fatal error"); askForInput = true; while (askForInput) { try { itemNumber = scnr.nextInt(); askForInput = false; if ((itemNumber <= 0)="" ||="" (itemnumber=""> 8)) { throw new Exception("Try again"); } catch (Exception excpt) { System.out.println("Dispensing item " askForInput = false; + itemNumbe
Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here