Java Exceptions: Your parents gave you an emergency cash card that has 2 restrictions:  it can't be used to purchase alcohol, and the purchase price must be less than $100.  Write a program segment in main() that will read 2 inputs from the user describing a purchase you are trying to make using the cash card:  the item purchased (eg runners) and the purchase price (eg 79.99).  Your code must check for the 2 restrictions mentioned above and generate exceptions if either one of them occurs (InvalidItemException or InvalidPurchasePriceException.  Assume that these have already been coded so you don't need to write them).  Your code must also deal with each exception by writing out an appropriate (specific) message stating what the problem is.  If there is no problem your code should generate a "Payment accepted" message.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

Java Exceptions:

Your parents gave you an emergency cash card that has 2 restrictions:  it can't be used to purchase alcohol, and the purchase price must be less than $100.  Write a program segment in main() that will read 2 inputs from the user describing a purchase you are trying to make using the cash card:  the item purchased (eg runners) and the purchase price (eg 79.99).  Your code must check for the 2 restrictions mentioned above and generate exceptions if either one of them occurs (InvalidItemException or InvalidPurchasePriceException.  Assume that these have already been coded so you don't need to write them).  Your code must also deal with each exception by writing out an appropriate (specific) message stating what the problem is.  If there is no problem your code should generate a "Payment accepted" message.

Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,