can someone please help me create a cheachkingAccoaunt Class In the super class,
ID: 3696948 • Letter: C
Question
can someone please help me create a cheachkingAccoaunt Class
In the super class, BankAccount, add the method, transfer(), which moves money from the bank account to another account.
one account (the current object) withdraws a given amount. The other deposits the amount. How many parameters are needed in this methods?
Of course, the method needs to throw exception(s) related to withdrawal and deposit operations.
Create a subclass, CheckingAccount class, of the BankAccount class
This type of account charges transaction fees after five free transactions. Each charged transaction is charged $3.00 Be careful! Use constant and static data member as needed.
The class includes the following methods:
A default constructor
A parameterized constructor with a parameter which throws exception(s) as needed
An overridden deposit method that throws exception(s) as needed
An overridden withdrawal method that throws exception(s) as needed
A method to deduct the accumulated fees and resets the transaction count to 0
toString() method to display the account information. For numeric data should be displayed with two decimal points
here is the BankAccount Class
abstract class BankAccount implements Serializable
{
//define the data fields
private double balance;
private int dNumber;
private int withdrawals;
private double annualInterest;
private double monthlyCharges;
private double interestRate;
private double monthlyRate;
private double monthlyInterest;
public BankAccount (double myBalance, double annual)throws InvalidDepositAmount
{
balance = myBalance;
annualInterest= annual;
getdNumber ();
withdrawals = 0;
}
public BankAccount (double myBalance, double myInetrestRate, double monthlyCharge)throws InvalidDepositAmount
{
balance = myBalance;
interestRate = myInetrestRate;
monthlyCharges= monthlyCharge;
depositNumber = 0;
withdrawals = 0;
}
/** the getMonthlyCharges access the monthly charges*/
public double getMonthlyCharges()
{
return monthlyCharges;
}
{
this.monthlyCharges = monthlyCharges;
}
public int getdNumber()
{
return dNumber;
}
{
return balance;
}
/** the getDeposit method access the deposit of saving account*/
public void deposit (double myDeposit) throws InvalidDepositAmount
{
if(myDeposit <=0 || myDeposit>10000)
{
throw new InvalidDepositAmount();
}
balance += myDeposit;
depositNumber +=1;
}
public double getWithdrawals ()
{
return withdrawals;
}
public void setWithdrawal (double myAmount) throws InvalidWithdrawalAmount
{
if(myAmount <=0 || myAmount>10000){
throw new InvalidWithdrawalAmount();
}
balance = balance - myAmount;
withdrawals += 1;
}
public void calcInterest ()
{
monthlyRate = (annualInterest/12);
monthlyInterest = balance* monthlyRate;
balance = balance + monthlyInterest;
return ;
}
{
balance -= monthlyCharges;
calcInterest ();
withdrawals = 0;
depositNumber = 0;
monthlyCharges = 0;
return ;
}
public void addServiceCharge (double amount)
{
monthlyCharges += amount;
}
public void setInterestRate (double annualInterest)
{
interestRate = annualInterest;
}
public double getInterestRate ()
{
return interestRate;
}
}
Explanation / Answer
Hi below i have written the class for checking account for your reference :) /** A checking account that charges transaction fees. */ public class CheckingAccount extends BankAccount { /** Constructs a checking account with a given balance. @param initialBalance the initial balance */ public CheckingAccount(double initialBalance) { // Construct superclass super(initialBalance); // Initialize transaction count transactionCount = 0; } public void deposit(double amount) { transactionCount++; // Now add amount to balance super.deposit(amount); } public void withdraw(double amount) { transactionCount++; // Now subtract amount from balance super.withdraw(amount); } /** Deducts the accumulated fees and resets the transaction count. */ public void deductFees() { if (transactionCount > FREE_TRANSACTIONS) { double fees = TRANSACTION_FEE * (transactionCount - FREE_TRANSACTIONS); super.withdraw(fees); } transactionCount = 0; } private int transactionCount; private static final int FREE_TRANSACTIONS = 5; private static final double TRANSACTION_FEE = 3.0; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.