[Java] Please fix what I did wrong The only class we can modify is TimeDepositAc
ID: 3573359 • Letter: #
Question
[Java] Please fix what I did wrong
The only class we can modify is TimeDepositAccount.
Any other classses, we can't.
The output should look like below:
The bold part is what I'm getting wrong.
Use the following files:
BankAccount.java
AccountTester.java
FeeBasedAccount.java
public class FeeBasedAccount extends BankAccount
{
public static final double TRANSACTION_FEE = 2.00;
public static final double FREE_TRANSACTIONS = 3;
private int transactions;
public FeeBasedAccount(double money, String idNumber)
{
super(money, idNumber);
transactions = 0;
}
@Override
public String getAccountId()
{
return super.getAccountId();
}
@Override
public void deposit(double amount)
{
super.deposit(amount);
transactions++;
}
@Override
public void withdraw(double amount)
{
super.withdraw(amount);
transactions++;
}
@Override
public double getBalance()
{
return super.getBalance();
}
@Override
public void endOfMonth()
{
double chargedTransactions = transactions - FREE_TRANSACTIONS;
double total = chargedTransactions * TRANSACTION_FEE;
if (transactions > FREE_TRANSACTIONS)
{
double balance = super.getBalance() - total;
this.withdraw(total);
}
}
}
Complete the following files:
TimeDepositAccount.java
public class TimeDepositAccount extends BankAccount //This account is a subclass of BankAccount.
{
public TimeDepositAccount(double initialBalance, String id, int months)
{
super(initialBalance, id);
maturity = months;
}
@Override
/**
* Deposits money into the bank account.
* @param in the amount to deposit
*/
public void deposit(double in)
{
super.deposit(in);
}
@Override
/**
* Withdraws money from the bank account.
* There is a penalty for early withdrawal.
* @param out the amount to withdraw
*/
public void withdraw(double out)
{
double fee = out * PENALTY;
super.withdraw(out);
if (maturity < 12)
{
super.withdraw(fee);
}
}
@Override
/**
* Do end of month processing for the account
*/
public void endOfMonth()
{
super.deposit(super.getBalance() * INTEREST);
}
/**
* a method that returns the amount of time the money must be left on deposit.
* @return maturity the amount of time the money must be left on deposit.
*/
public int getTimeToMaturity()
{
return maturity;
}
}
Explanation / Answer
In TimeDepositAccount class, it is required to set static constants-'INTEREST' and 'PENALTY' to expected value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.