Design and implement the following 3 classes with the exact fields and methods (
ID: 3867002 • Letter: D
Question
Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly):
Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly) 1. An abstract class named BankAccount (iava file called BankAccount.java) Filed/Method Balance NumberDeposits NumberWithdrawals AnnuallnterestRate MonthlyServiceCharge BankAccount SetMonthlyServiceCharges A method that accepts the monthly service charges as an argument and set the field value GetBalance GetNumberDeposits GetNumberWithdrawals GetAnnualinterestRate GetMonthlyServiceCharge A method that returns the monthly service charge Deposit Description A field for the bank account balance A field for the number of deposits this month A field for the number of withdrawals this month A field for the annual interest rate A field for the monthly service charge A constructor method that accepts as arguments the balance and the annual interest rate A method that returns the bank account balance A method that returns the number of deposits this month A method that returns the number of withdrawals this month A method that returns the annual interest rate A method that accepts the amount of the deposit as an argument, add the value of that argument to the account balance, and increment the variable holding the number of deposits. A method that accepts the amount of the withdrawal as an argument, subtracts that argument value from the balance, and increment the value holding the number of withdrawals. A method that updates the balance by calculating the monthly interest earned by the account ( MonthlyInterest - Balance Anualinteresthkate) MonthlyInterest) A method that subtracts the monthly service charges from the balance, callas the Calculatelnterest method to calculate the interest, and then sets to 0 the variables for NumberDeposits, NumberWithdrawals, and MonthlyServiceCharge Withdrawa Calculatelnterest , and adding this interest to the balance (Balance= Balance + 12 MonthlyProcessExplanation / Answer
abstract class BankAccount
{
private double Balance;
private int NumberDeposits;
private int NumberWithdrawals;
private double AnnualInterestRate;
private double MonthlyServiceCharge;
public BankAccount(double Balance,double AnnualInterestRate)
{
this.Balance = Balance;
this.AnnualInterestRate = AnnualInterestRate;
}
public void SetMonthlyServiceCharges(double MonthlyServiceCharge)
{
this.MonthlyServiceCharge = MonthlyServiceCharge;
}
public double GetBalance()
{
return Balance;
}
public int GetNumberDeposits()
{
return NumberDeposits;
}
public int GetNumberWithdrawals()
{
return NumberWithdrawals;
}
public double GetAnnualInterestRate()
{
return AnnualInterestRate;
}
public double GetMonthlyServiceCharge()
{
return MonthlyServiceCharge;
}
public void Deposit(double amount)
{
Balance = Balance + amount;
NumberDeposits++;
}
public void Withdrawal(double amount)
{
Balance = Balance - amount;
NumberWithdrawals++;
}
public void CalculateInterest()
{
double MonthlyInterest = Balance * AnnualInterestRate/12;
Balance = Balance + MonthlyInterest;
}
public void MonthlyProcess()
{
Balance = Balance - MonthlyServiceCharge;
CalculateInterest();
NumberDeposits = 0;
NumberWithdrawals = 0;
MonthlyServiceCharge = 0;
}
}
class SavingsAccount extends BankAccount
{
private boolean Status;
public SavingsAccount(double Balance,double AnnualInterestRate,double MonthlyServiceCharge)
{
super(Balance,AnnualInterestRate);
SetMonthlyServiceCharges(MonthlyServiceCharge);
if(Balance < 25)
Status = false;
else
Status = true;
}
public void Deposit(double amount)
{
super.Deposit(amount);
if(GetBalance() < 25)
Status = false;
else
Status = true;
}
public void Withdrawal(double amount)
{
if(Status == true)
super.Withdrawal(amount);
if(GetBalance() < 25)
Status = false;
else
Status = true;
}
public void MonthlyProcess()
{
if(GetNumberWithdrawals() <= 4)
super.MonthlyProcess();
else
{
SetMonthlyServiceCharges(GetNumberWithdrawals()-4);
super.MonthlyProcess();
}
}
}
class NameAssignment3
{
public static void main (String[] args)
{
SavingsAccount sa = new SavingsAccount(1200,1.2,2);
System.out.println("Balance : "+sa.GetBalance());
sa.Deposit(250);
sa.Deposit(100);
System.out.println(" Annual Interest : "+sa.GetAnnualInterestRate());
System.out.println("Monthly Service Charge : "+ sa.GetMonthlyServiceCharge());
sa.Withdrawal(150);
System.out.println("Number of Deposits : "+sa.GetNumberDeposits());
System.out.println("Number of Withdrawals : "+sa.GetNumberWithdrawals());
sa.CalculateInterest();
System.out.println("Balance after interest : "+sa.GetBalance());
sa.MonthlyProcess();
System.out.println("Balance after monthly process : "+sa.GetBalance());
}
}
Output:
alance : 1200.0
Annual Interest : 1.2
Monthly Service Charge : 2.0
Number of Deposits : 2
Number of Withdrawals : 1
Balance after interest : 1540.0
Balance after monthly process : 1691.8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.