[SOLVED] CS212 Lab 20-Adding Exceptions to Money

25.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab20-pg4sop.zip (39.7 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
Rate this product

Adding Exceptions to Money.

Rather than create a new project in Eclipse for Lab 20, we will add to the Lab18 project.

Import the class BadWalletMain from Z:\Lab20, and look at the code. The array of strings now contains bas instances of bills, such as “B18” and “BAD”.

Create a new exception class called IllegalBillException that extends

IllegalArgumentException (see the lecture on Exceptions if you do not remember how to do this.) Modify class Bill so that is throws a new IllegalBillException is the amount of the bill is not 1, 5, 10, 20, 50 or 100 (there are more bills, but that’s enough.)

Enclose the for loop in class BadWalletMain with a try/catch block that will catch the IllegalBillException and print the errant string to the console, and continue the for loop.. Include a catch clause for the case of the string “BAD” as well.

Run BadWalletMain and see that it terminates normally.

  • Lab20-pg4sop.zip