The following program simulates a vending machine panel. The program gets an integer that represents the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image 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 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 <= 0) || (itemNumber > 8)) { throw new Exception ("Try again"); } System.out.println("Dispensing item askFor Input = false; I + itemNumbe 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 <= 0) || (itemNumber > 8)) { throw new Exception ("Try again"); } System.out.println("Dispensing item askFor Input = false; I + itemNumbe
Expert Answer:
Answer rating: 100% (QA)
import javautilScanner import javautilInputMismatch... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
What is the best way to describe automation? developing highly advanced robots that can mimic higher-levelhuman thinking making human workers fully reliant on technology to performtheir job...
-
The T-accounts below summarize the ledger of Salvador's Gardening Company, Inc. at the end of the first month of operations. Instructions (a) Prepare the journal entries (including explanations) that...
-
Assume the following about Taco Corporation: Tax rate is 21% There are 20,000 $1,000 par, 5% coupon semi-annual bonds outstanding (this is the only debt). These bonds are selling at 94% of par and...
-
Is a winwin situation the only practical way to move business towards sustainability?
-
Pope's Garage had the following accounts and amounts in its financial statements on December 31, 2016. Assume that all balance sheet items reflect account balances at December 31, 2016, and that all...
-
Describe approach to assessing the competitive market for craft breweries in Canada: Describe the number of competitors and relative size of the industry. NOTE: use proxy data - demonstrate to...
-
Problem Statement: The aim of this case study is to propose a daily capacity level and level of resourcing required for Q2 & Q3 2023. The proposed daily capacity level should achieve the highest...
-
Describe the principles of security operations Describe key security policies and procedures Describe major security technologies with pros and cons Follow APA 7th edition guidelines. Ensure you use...
-
ADIB has signed a Musharaka contract with ADIA. ADIB provided 41 % capital contribution in the project and agreed to the same profit-sharing percentage (41%). In addition, ADIB appointed ADIA as a...
-
How is Dasani getting the advertising message to the consumer?
-
A coil of 40 turns and cross-sectional area 1.73 m is oriented perpendicular to a magnetic field, which varies from zero to 2.37 Tin 2.56 s. What emf is induced in the coil? Use two decimal places...
-
In (3x+7) Find the slope of f(x) = at (6, 1.58). Use a graphing utility and round to the nearest hundredth. 3
-
How can collaboration and communication tools integrated into an information system enhance the teamwork and productivity of laboratory project participants?
-
Fully simplify each of the following expressions. (a) (b) (c) 14 1-1-12 +(3 marks) + 3+1 + 3 27 3-1 2 +3 T - y (z + y) (2-y) (2 marks) (3 marks)
-
How does the organizational structure of an MNC influence its strategy implementation?
-
Create a UsedCarException class that extends Exception; its constructor receives a value for a vehicle identification number (VIN) that is passed to the parent constructor so it can be used in a...
-
To encourage good grades, Hermosa High School has decided to award each student a bookstore credit that is 10 times the students grade point average. In other words, a student with a 3.2 grade point...
-
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the...
-
In a recent year Kennedy Ltd had profit after tax of \($150\) 000, interest expense of \($30\) 000, and tax expense of \($20\) 000. What was Kennedy Ltds times interest earned for the year? (a) 5.00....
-
An obligation for long service leave payable 6 years from now is recognised as: (a) a contingent liability. (b) a non-current provision. (c) a current provision. (d) none of the above; it is not...
-
Gester Ltd redeems its \($100\) 000 face value debentures at 105 on 31 January, following the payment of half-yearly interest. The carrying amount of the debentures at the redemption date is \($100\)...
Study smarter with the SolutionInn App