CSCI 217: Advanced Computer Programming
Assignment 1: Classes and Inheritance
Question 1:
In this assignment we will simulate a bank transaction. Program Specification and
implementation:
Create a superclass BankAccount and two subclasses CheckingAccount and SavingsAccount. All
the bank accounts should support getBalance, deposit and withdraw methods. Follow the
below detailed specifications for each class.
BankAccount:
- Create a balance attribute
- Constructor initialize the account balance with 0.
- Parameterized constructor take balance and assign it to account balance attribute.
- deposit method that takes an amount to be deposited.
- withdraw method that takes amount to withdraw.
- getBalance method to return the current balance in the account.
- transferMoney method that transfers money from this bank account to other bank account.
This method takes two arguments (BankAccount otherAccount, double amount).
- display method that displays the account balance.
CheckingAccount:
- Constant instance fields for ALLOWED_TRANS and TRANS_FEE. Allow for 2 free transactions
and $3 for additional transaction.
- instance field transactionCount (specific and new to CheckingAccount).
- Constructor initialize the account balance with 0.
- Parameterized constructor take balance and assign it to account balance attribute.
- override deposit and withdraw methods to increment the transaction count.
- chargeFees that charges transaction fee if any to the account at the end of the period.
SavingsAccount:
- Instance field interestRate that holds the interest rate for period.
- Constructor that sets interest rate.
- Constructor that sets rate and initial balance.
- addCompoundInterest method that adds the interest for the current period to the account
balance. Deposit the interest to the account. (Use this formula to calculate interest = balance *
interestRate / 100.0 )
TransactionsDriver:
- Instantiate a savings account name it dadsSavings with interestRate 0.3%
- Instantiate a checking account and name it kidsChecking.
- Deposit 10000 into dadsSavings account.
- Transfer 3000 to kidsChecking
- Withdraw 200 from kidsChecking
- Withdraw 400 from kidsChecking
- Withdraw 300 from kidsChecking
- Withdraw 500 from kidsChecking
- Withdraw 400 from kidsChecking
- Invoke end of period interest for the savings account
- Invoke end of period transactions fees for the checking account
- Display the final balance for dadsSavings account
- Display the final balance for kidsChecking account
- End of program
Sample Output:
At the end of these transactions the bank accounts should have the below balances:
End of the period account balances.
Dad's savings. Account balance: 7021.0
kid's checking. Account balance: 1188.0
Question 2:
Translate the UML diagram into a complete Java code. Then, write a test program to test all the
methods defined in Shape.
Note:
Due Date: on Thursday, 16 March 11:59 PM.
Delay Policy: Late submissions are not allowed.
Submissions will be on Moodle ONLY (not by email).
NOTE: Submit your assignment individually (no teams are permitted).
If plagiarism is DETECTED or SUSPECTED, tough actions will be applied.