01.11.10 - 05.09.10
InsufficientFundsError class created | 20 pts |
NegativeAmountError class created | 20 pts |
Exception raised when negative amount is given | 10 pts |
Exception raised when there is insufficient funds | 10 pts |
NegativeAmountError is rescued | 10 pts |
InsufficientFundsError is rescued | 10 pts |
Output from NegativeAmountError is correct | 10 pts |
Output from InsufficientFundsError is correct | 10 pts |
Total | 100 pts |
For this assignment you will need to improve on the BankAccount program. To do this you will need to create two custom exception classes called InsufficientFundsError and NegativeAmountError which will represent those two conditions.
The BankAccount class should be modified to raise these exceptions when the corresponding error occurs within the class. (i.e. when the user tried to withdraw more than is in the account the InsufficientFundsError should be raised)
The "driver" part of the program that runs the menu system and allows the user to input choices will also need to be modified to rescue these exceptions. When either of these exceptions is rescued in the driver it should puts the exception, displaying the return from it's to_s method to the console.
The to_s method of the InsufficientFundsError class should return a string like:
"Account [id] has insufficient funds ($[balance]) to allow the withdrawal of $[amount]"
where [id] is the account number of the account that was being acted upon, [balance] is the balance of that account, and [amount] is the amount the user tried to withdraw.
The to_s method of the NegativeAmountError class should return a string like:
"You cannot [action] a negative amount for account [id]"
where [action] is the action the user was taking on the account (deposit or withdraw), and [id] is the id number of the account that was being acted upon.