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 work done by a conservative force is indicated in FIGURE 8-23 for a variety of different paths connecting the points A and B. What is the work done by this force (a) On path 1 (b) On path 2? W =...
-
Rank the following occupations as to your perception of their honesty and ethical standards: clergy, bankers, lawyers, medical doctors, high school teachers, police officers, car salespeople, members...
-
Almetals, Inc., a Michigan company, entered into a contract with the German firm Wickeder Westfalenstahl regarding the purchase of clad metal, a specialty metal used in a variety of industries but...
-
Animal Gear Company makes two pet carriers, the Cat-allac and the Dog-eriffic. They are both made of plastic with metal doors, but the Cat-allac is smaller. Information for the two products for the...
-
Ann wants to start a business that processes blueberries so that they are easier for people to store for the winter. How would transportation costs between Bethel and outside of Alaska help or hurt...
-
Exercise 6.1 Configuring Memory on Paper Objective: a computer is not performing as well as it used to. Windows 10 tool would the technician get the user to open to quickly tell how much RAM is...
-
Hello I have an exam, (Today) on Monday 10/8/2020, from 7:45 Pm to 8:30 Pm, the time of the State of Jordan, on the following topic: (Advanced Physics) - The exam will also be in English. - The exam...
-
Compute the indicated limit. Write your answer as a fraction, if necessary. r _52+4 -x-12 lim x 4x.
-
a 5 4 0 kg spacecraft weighs 8 1 0 N on the surface of planet equity. what is the acceleration due to gravity on the planet's surface?
-
If a 2 kg ball is falling with a terminal speed, what is the force (in newtons) of the air resistal on the ball? (use g = 10 m/s)
-
Using f(x)=x-6 Find (9-3)
-
6. A North American river otter wants to cross the North Saskatchewan river. It can swim at a speed of 2.75 m/s. In that location, the distance directly across the river is 45.0 m. a) How much time...
-
An unsymmetrical parabolic curve has a forward tangent of 5% and a backward tangent of -3%. The length of the curve on the left side of the curve is 120m while that of the right side is 90m.If the...
-
The landing gear of an aircraft with: mass of 2000 kg the spring-mass-damper system Consider that the runway surface is y(t) = 0.2 cos 157.08t stiffness of the spring is 5 x 105 N/m. What is the...
-
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...
-
Which of the following types of epigenetic changes may promote cancer? a. DNA methylation b. Covalent modification of histones c. Chromatin remodeling d. All of the above may promote cancer.
-
The underlying cause(s) of epigenetic changes associated with cancer may be a. mutations in genes that encode chromatin-modifying proteins. b. environmental agents that alter the function of...
-
Normal (nonmutant) tumor-suppressor genes often function a. as negative regulators of cell division. b. in the maintenance of genome integrity. c. in the stimulation of cell division. d. as both a...
Study smarter with the SolutionInn App