CIS 180: Object-Oriented Programming
Homework #4

Bank Accounts

Due Tuesday, October 13, 2009

Problem Statement

This assignment is to code working solutions to problems 8 and 9 from the first midterm practice exam. Consider a java Account class for bank account objects:

The fields of this class should be declared protected instead of private. The default constructor should print an error message saying you cannot create an account without specifying an account number and initial balance.

The other constructor method and the deposit and with withdraw methods should print "receipts" on the console. If a request is made to withdraw more money than is in the account, an error message should be printed and the account balance left unchanged. The following example shows how the Account class could be used in an application:


public class BankingApplication {

    public static void main(String[] args) {
        Account a1 = new Account(101, 500);
        a1.deposit(50);
        a1.withdraw(100);
        a1.withdraw(800);
        a1.deposit(20);
     }
}

The example application shown above should produce the following output:


Opened account 101 with initial balance of $500.00

Deposited $50.00 in account 101
The new balance is: $550.00

Withdrew $100.00 from account 101
The new balance is: $450.00

Error: Insufficient funds for 
withdrawal of $800.00 from account 101

Deposited $20.00 in account 101
The new balance is: $470.00

Next, consider an OverdraftAccount class. Overdraft accounts are similar to regular accounts except that they can be overdrawn (have a negative balance) up to a preset limit. The constructor for OverdraftAccounts should take the account number, initial balance, and overdraft limit as parameters. If a withdrawal request would result in exceeding the overdraft limit, an error message should be printed and the account balance left unchanged.

Design and Implementation

Your design should consist of a UML class diagram showing three classes: Account, OverdraftAccount, and BankingApplication. Include all details (types, parameters, accessibility). Your eclipse project should contain implementations of all three classes. Complete and test the Account class before you attempt to implement the OverdraftAccount class. You should add code to the main method you are given in the BankingApplication class to test the OverdraftAccount class.

What to turn in

Submit your source code (Account.java, OverdraftAccount.java, and BankingApplication.java) files as well as your class diagram as email attachments to: ttao@umassd.edu. Alternatively, you may submit your class diagram in hardcopy.

Use the subject line CIS-180 HW#4 in your email.