You are given a BankAccount class. You are to write two subclasses: TransactionA
ID: 3808846 • Letter: Y
Question
You are given a BankAccount class. You are to write two subclasses: TransactionAccount and InterestAccount
BankAccount:
This class is provided for you. It is different from earlier versions in that it requires a minimum balance of $1500. There is a $10.00 fee for any month where the ending balance is below the minimum balance. There is an endOfMonth method to handle end of month processing. Its subclasses will handle end of month processing differently.
TransactionAccount:
This account is a subclass of BankAccount. It has no minimum balance, but there is a charges for every transaction after a certain number of free transactions. At the current time, the number of free transactions is 4 and the charge is a $5.00 for every transaction after that amount. Both deposits and withdrawals are transactions. There is no charge to get the balance. The fees are subtracted during end of month processing. Define and use constants.
InterestAccount:
This is a subclass of BankAccount. The owner of the account can deposit or withdraw money at any point. The account earns 0.9% interest annually compounded monthly. Interest is paid on the ending balance during end of month processing. Use a constant for annual interest rate.
Provide Javadoc. You can use @Override for overridden methods.
Use the following files:
AccountTester.java
BankAccount.java
Explanation / Answer
TransactionAccount.java:
public class TransactionAccount extends BankAccount {
public final static int FREE_TRANSACTIONS = 4;
public final static int TXN_CHARGE = 5;
private int transaction_in_month = 0;
public TransactionAccount(double initialBalance, String id) {
super(initialBalance, id);
}
/**
* Deposits money into the bank account.
*
* @param amount
* the amount to deposit
*/
public void deposit(double amount) {
super.deposit(amount);
transaction_in_month++;
}
/**
* Withdraws money from the bank account.
*
* @param amount
* the amount to withdraw
*/
public void withdraw(double amount) {
super.withdraw(amount);
transaction_in_month++;
}
public void endOfMonth() {
if (transaction_in_month > FREE_TRANSACTIONS) {
transaction_in_month = transaction_in_month - FREE_TRANSACTIONS;
super.setBalance(super.getBalance() - transaction_in_month * TXN_CHARGE);
}
transaction_in_month = 0;
}
}
InterestAccount.java:
public class InterestAccount extends BankAccount {
public final double RATE = 0.9;
public InterestAccount(double initialBalance, String id) {
super(initialBalance, id);
}
public void endOfMonth() {
double balance = getBalance();
balance = balance + balance* RATE/1200;
setBalance(balance);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.