Question: Coin Name and Coin Value Exception Classes Create two exception classes to capture the improper entering of coin names and their corresponding values. Name one

Coin Name and Coin Value Exception Classes Create two exception classes to capture the improper entering of coin names and their corresponding values. Name one class CoinNameException and the other CoinValueException. Design and write a program that asks a young child to input a set of coin names and their corresponding values (in cents) in their piggybank. The program should work in a loop: First, the program should prompt the child to enter the name of a coin (penny, nickel, dime, quarter, or half-dollar). If an improper name for a coin is entered, then catch a CoinNameException exception, print an error message, and give the child a second chance to reenter it. After two chances, terminate the program. Once a valid coin name has been entered in step #1 above, the child must then enter the corresponding value of that coin in cents (1, 5, 10, 25, or 50). Use either the Integer.parseInt() or the nextInt() method to get the value of the coin. Hint: What exceptions can these methods throw? If the child enters the wrong value for the coin, then catch a CoinValueException exception, print an error message, and give the child a second chance to reenter the value of the coin. After two chances, terminate the program. If a valid coin and its corresponding value are entered, add that coin to the childs piggybank total and go back to step #1 Other than entering an invalid coin name or value twice, provide a nicer and simpler way for the child to exit the loop above (steps 1 3) When the child is finished entering coins (or the program terminates), display a nicely-formatted report showing the name, value, and quantity of each coin in the childs piggybank, along with the total value of all coins.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!