CS230 Assignment 4

Assignment 4

 

DUE: Thursday Oct 10 at 11:59pm

  • How to turn in your assignment There is only one individual task. Remember to include a text file showing testing of your solution, e.g., the contents of the BlueJ Terminal Window demonstrating correct executions of your program on various sample data (don't forget edge cases!)
  • To Gradescope, submit 5 files: Bank.java, Account.java, SavingsAccount.java, CheckingAccount.java and your text file with the testing transcript BankTesting.txt. Make sure you are using JavaDoc documentation style.
  • To your account on the CS Server (in your public_html/cs230-assignments/ps04) folder upload a zip file of all materials.
  • Finally, submit the Cover page.
 

Goals:

  • Understanding Java's hierarchy structure
  • Understanding abstract classes and polymorphic variables
  • Start thinking about designing a hierarchical solution from specifications
 

Task: Create your own Bank!

...Or at least create the basic software that will deal with account creation, deposits and withdrawals. Below are the rules that were given by the Bank Manager, a Wellesley graduate with CS230 experience (and a passion for creating classes through inheritance ;-) Her rules are carefully worded: Almost every sentence has some coding implication or hint. You really do not want to disappoint her -- read carefully!

Design and implement 4 classes – Account, CheckingAccount, SavingsAccount, and Bank. Note that CheckingAccount is-a Account, SavingsAccount is-a Account, while Bank contains a collection of accounts. Consider this inheritance implication when designing the first three classes. According to the Banking policy, nobody ever creates just an Account - they may only create either a SavingsAccount or a CheckingAccount.

The Account class, includes an account number, an account balance, a deposit method and a method to print itself. It also includes a withdraw method, which, however, has no specific code associated with it! (Think about what does this mean!) Deposits work the same way no matter what kind of account you deposit to: the deposited amount simply is added to its balance. The management needs to make sure that no other code can override this method! In order to create a new account, some initial deposit is required, along with a unique account number. To print the contents of an Account, you should display the account number and the balance in a nicely formatted way. See below in the printout area for a way to do that.

A CheckingAccount class has, in addition to the information in Account, a minimum balance ($100) and an overdraft fee ($25). Its withdraw method allows overdrafts (withdrawing below the minimum balance but not below $0); however the overdraft fee is incurred if the balance drops below the minimum balance. If there is not enough money to cover the fee, the transaction is allowed but no further withdrawal is permitted until a deposit is made to bring the funds above the minimum balance. When printing a CheckingAccount you should display everything the Account displays plus the minimum balance. The Account display method should do most of the work.

The SavingsAccount has no minimum balances or overdraft fees, but it has an annual interest rate (currently 1.5%). It also has a method to recalculate the balance every month by adding the monthly interest to its balance. (Assume that the recalculate method is only called manually once a month, no need to keep track of dates.) Since the interest rate is annual, make sure to calculate the monthly interest accordingly. The class also has a method to display everything the Account displays plus the interest rate. Here, also, you should use the Account display method to do most of the work.

Finally, the Bank class contains a collection of accounts in an array and it keeps track of the number of accounts that have been opened. To make things simple, have the constructor create a few accounts so that you do not have to add methods to add an account (as we saw with the Staff constructor in class). Bank contains a method findAccount(int acctNum) which locates the Account with a given account number. It also contains a method of printing all the accounts along with a method to computeTotalFunds that returns the funds that are held all of the accounts together, checking and savings. To show that your programs works correctly, you should create a main to show correct usage of the project. It is recommended that your main prints the correct results it expect to compute so that you check that your calculations are correct.

An example of running the program is given below.

$ java Bank
Current state of Bank accounts:
Checking Acct#: 0 Balance: $1,000.00 Minimum balance = 100
Savings Acct#: 1 Balance: $1,000.00 Interest rate: 1.5%
Checking Acct#: 2 Balance: $500.00 Minimum balance = 100
Savings Acct#: 3 Balance: $500.00 Interest rate: 1.5%
Total Funds: $3000.0

[Depositing into Checking 0. Should print Acct#1, Bal=$5000, Min=$100]
Checking Acct#: 0 Balance: $5,000.00 Minimum balance = 100

[Depositing into Savings 1. Should print Acct#2, Bal=$3000, Int=1.5%]
Savings Acct#: 1 Balance: $3,000.00 Interest rate: 1.5%

[Recalculating balance on 2nd account: Bal=$3,003.75]
Savings Acct#: 1 Balance: $3,003.75 Interest rate: 1.5%

[Withdrawing $6K -- MORE THAN AVAILABLE from Checking]
Withdrawal DENIED: Amount in Checking is greater than balance.
Checking Acct#: 0 Balance: $5,000.00 Minimum balance = 100

[Withdrawing $4901 triggers Overdraft: Bal=$74.00]
NOTE: Under min limit: Fee assessed.
Checking Acct#: 0 Balance: $74.00 Minimum balance = 100

[Withdrawing $5K MORE THAN AVAILABLE from Savings]
**Withdrawal DENIED: Amount in Savings is greater than balance.
Savings Acct#: 1 Balance: $3,003.75 Interest rate: 1.5%

New state of Bank accounts:
Checking Acct#: 0 Balance: $74.00 Minimum balance = 100
Savings Acct#: 1 Balance: $3,003.75 Interest rate: 1.5%
Checking Acct#: 2 Balance: $500.00 Minimum balance = 100
Savings Acct#: 3 Balance: $500.00 Interest rate: 1.5%
Total Funds: $4077.75