SDSU CS 535 Object-Oriented Programming
Spring Semester, 2003
Assignment 5
    Assignment Index        
© 2003, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 04-Mar-03

Assignment 5

Due March 13

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

Copyright ©, All rights reserved.
2003 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

    visitors since 04-Mar-03