Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: BankAccount class and SavingsAccount class Design an abstract class na

ID: 3775374 • Letter: Q

Question

Question: BankAccount class and SavingsAccount class

Design an abstract class named BankAccount to hold the following data for a bank account:

Balance

Number of deposits this month

Number of withdraws this month

Annual interest rate

Monthly service charges

The class should have the following methods:

A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:

Monthly Interest Rate = Annual Interest Rate / 12

Monthly Interest = Balance * Monthly Interest Rate

Balance = Balance + Monthly Interest

Next, design a SavingsAccount class to extend the BankAccount class. The SavingsAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below $25, it becomes inactive. (The status field can be a boolean variable.) No more withdrawals may be made until the balance is raised above $25, at which the account becomes active again. The SavingsAccount class should have the following methods:

Then write a program to create objects from the SavingsAccount class to demonstrate the two classes.

Submission: .java file only (3 java files: BankAccount.java, SavingsAccount.java, and the demonstrate program)

Constructor The constructor should accept arguments for the balance and annual interest rate deposit A method that accepts argument for the amount of the deposit. The method should add the argument to the amount of balance. It should also increment the variable holding the number of deposits withdraw A method that accepts argument for the amount of the withdrawal. The method should minus the argument from the amount of balance. It should also increment the variable holding the number of withdrawals calcInterest

A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:

Monthly Interest Rate = Annual Interest Rate / 12

Monthly Interest = Balance * Monthly Interest Rate

Balance = Balance + Monthly Interest

monthlyProcess A method that subtracts the monthly service charges from the balance, calls the calculateInterest method, and then set the variables that hold the number of deposits, number of withdrawals, and monthly service charges to zero.

Explanation / Answer

PROGRAM CODE:

BankAccount.java

package bankaccount;

public class BankAccount {

  

   double balance;

   int numberOfWithdrawalsPerMonth;

   int numberOfDepositsPerMonth;

   double annualInterestRate;

   int monthlyServiceCharges;

  

   public BankAccount(double bal, double interestRate) {

       this.balance = bal;

       this.annualInterestRate = interestRate;

   }

  

   public void deposit(double amount)

   {

       balance += amount;

       numberOfDepositsPerMonth++;

   }

  

   public void withdraw(double amount)

   {

       balance -= amount;

       numberOfWithdrawalsPerMonth++;

   }

  

   public void calcInterest()

   {

       double monthlyInterestRate = annualInterestRate/12;

       balance += balance * monthlyInterestRate;

   }

  

   public void monthlyProcess()

   {

       balance -= monthlyServiceCharges;

       calcInterest();

       numberOfDepositsPerMonth = 0;

       numberOfWithdrawalsPerMonth = 0;

       monthlyServiceCharges = 0;

   }

   public int getMonthlyServiceCharges() {

       return monthlyServiceCharges;

   }

   public void setMonthlyServiceCharges(int monthlyServiceCharges) {

       this.monthlyServiceCharges = monthlyServiceCharges;

   }

  

  

}

SavingsAccount.java

package bankaccount;

public class SavingsAccount extends BankAccount{

   boolean status;

  

   public SavingsAccount(double bal, double interestRate) {

       super(bal, interestRate);

       if(balance < 25)

       {

           status = false;

       }

       else status = true;

   }

  

   public void withdraw(double amount)

   {

       if(status)

           super.withdraw(amount);

       if(balance < 25)

           status = false;

   }

  

   public void deposit(double amount)

   {

       if(status)

           super.deposit(amount);

       else if(balance + amount >=25)

           super.deposit(amount);

   }

  

   public void monthlyProcess()

   {

       int charges = 1;

       if(numberOfWithdrawalsPerMonth > 4)

       {  

           for(int i=4; i<numberOfWithdrawalsPerMonth; i++)

           {

               charges++;

           }

           setMonthlyServiceCharges(charges);

       }

       else

           setMonthlyServiceCharges(0);

       super.monthlyProcess();

       if(balance < 25)

           status = false;

   }

}

BankDriver.java

package bankaccount;

public class BankDriver {

   public static void main(String[] args) {

      

       SavingsAccount savingsaccount = new SavingsAccount(100, 10);

       System.out.println("Savings Account: ");

       System.out.println("Balance: " + savingsaccount.balance);

       savingsaccount.withdraw(50);

       System.out.println("Balance: " + savingsaccount.balance);

       savingsaccount.deposit(20);

       System.out.println("Balance: " + savingsaccount.balance);

       savingsaccount.withdraw(50);

       System.out.println("Balance: " + savingsaccount.balance);

       savingsaccount.withdraw(20);

       System.out.println("Balance: " + savingsaccount.balance);

       savingsaccount.monthlyProcess();

       System.out.println("After Monthly Processing: " + savingsaccount.balance);

      

       BankAccount bankaccount = new BankAccount(100, 7);

       System.out.println("Bank Account: ");

       System.out.println("Balance: " + bankaccount.balance);

       bankaccount.withdraw(50);

       System.out.println("Balance: " + bankaccount.balance);

       bankaccount.deposit(20);

       System.out.println("Balance: " + bankaccount.balance);

       bankaccount.withdraw(50);

       System.out.println("Balance: " + bankaccount.balance);

       bankaccount.setMonthlyServiceCharges(1);

       bankaccount.monthlyProcess();

       System.out.println("After Monthly Processing: " + bankaccount.balance);

   }

}

OUTPUT:

Savings Account:

Balance: 100.0

Balance: 50.0

Balance: 70.0

Balance: 20.0

Balance: 20.0

After Monthly Processing: 36.66666666666667

Bank Account:

Balance: 100.0

Balance: 50.0

Balance: 70.0

Balance: 20.0

After Monthly Processing: 30.083333333333336

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote