
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Put unused code in the right order

Transcribed Image Text:Unused
catch (InputMismatch Exception excpt) {
System.out.println("Fatal error");
askForInput = false;
}
catch (Exception excpt) {
System.out.println(excpt.getMessage());
askForInput
}
=
true;
System.out.println (excpt.toString());
System.out.println (excpt);
![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 Input Mismatch Exception, outputs "Fatal error", and then exits.
Not all lines are used in the solution.
How to use this tool
Unused
catch (InputMismatch Exception excpt) {
System.out.println("Fatal error");
askForInput
=
false;
}
catch (Exception excpt) {
System.out.println(excpt.getMessage());
}
askForInput = true;
System.out.println(excpt.toString());
System.out.println(excpt);
Vending Machine.java
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
int itemNumber = 0;
boolean askFor Input = true;
}
while (askForInput) {
try {
}
}
Load default template...
itemNumber = scnr.nextInt ();
if ((itemNumber <= 0) || (itemNumber > 8)) {
throw new Exception ("Try again");
}
System.out.println("Dispensing item " + itemNumbe
askFor Input = false;](https://content.bartleby.com/qna-images/question/0cc153ae-b205-4fb2-9991-7cf6a21d5016/4ce82dbe-afae-474d-8a7d-08abaebf1ccc/k9lxr4a_thumbnail.png)
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 Input Mismatch Exception, outputs "Fatal error", and then exits.
Not all lines are used in the solution.
How to use this tool
Unused
catch (InputMismatch Exception excpt) {
System.out.println("Fatal error");
askForInput
=
false;
}
catch (Exception excpt) {
System.out.println(excpt.getMessage());
}
askForInput = true;
System.out.println(excpt.toString());
System.out.println(excpt);
Vending Machine.java
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
int itemNumber = 0;
boolean askFor Input = true;
}
while (askForInput) {
try {
}
}
Load default template...
itemNumber = scnr.nextInt ();
if ((itemNumber <= 0) || (itemNumber > 8)) {
throw new Exception ("Try again");
}
System.out.println("Dispensing item " + itemNumbe
askFor Input = false;
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- kotlin langauge print this using loop 1 2 3 2 3 4 5 4 3 ... upto 5 rowsarrow_forwardplease don't change variable namesarrow_forwardpython - Recap: X is an array from -3pi to 8pi in 1000 steps. Write the python syntax for looping over all values of X and updating the value current to -999. where X is an even multiple of pi. Hint, use a for loop and appropriate if statements.arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education