1.
Create an exception NegativeBalance as a subclass of RangeError. Modify your
BankAccount class to throw the error when a withdrawal would make the account
balance negative. Write a test case that tests to insure the exception is
thrown when an account balance would be come negative.
2.
The bank needs a way to uniquely identify different accounts. Different people
can have the same name. People addresses and phone numbers change over time.
Some people do not have social security numbers. So none of these are good for
identifying an account. We need to generate an id for each new account. For
simplicity we will use an increasing sequence of integers starting at 1 for the
account ids. Use a class instance variable in the bank account to hold the next
available account id. Modify your BankAccount class to:
a.
Give each new BankAccount a unique ID.
b.
Override the = method to return true when comparing two BankAccounts with the
same ID
c.
Override the hash method to return a hash based on the ID
Write
test cases for a, b, and c.
For
problems 1 & 2 just turn in the source code for your tests and the
BankAccount class