5
answers
1
watching
256
views

import java.util.Scanner;

 

public class BankAccount {   protected double balance;   private int numOfDeposits;   protected int numOfWithdrawals;   private double annualInterestRate;

 

  public BankAccount(double balance, double annualInterestRate) {     this.balance = balance;     this.annualInterestRate = annualInterestRate;   }

 

  public void deposit(double amount) {     balance += amount;     numOfDeposits++;   }

 

  public void withdraw(double amount) {     balance -= amount;     numOfWithdrawals++;   }

 

  public void calcInterest() {     double monthlyInterestRate = (annualInterestRate / 12);     double monthlyInterest = balance * monthlyInterestRate;     balance += monthlyInterest;   }

 

  public void monthlyProcess() {     balance -= (numOfWithdrawals + numOfDeposits);     calcInterest();     numOfWithdrawals = 0;     numOfDeposits = 0;   } }

 

class SavingsAccount extends BankAccount {   private boolean status;

 

  public SavingsAccount(double balance, double annualInterestRate) {     super(balance, annualInterestRate);     status = balance >= 25;   }

 

  public void withdraw(double amount) {     if (!status) {       System.out.println("The savings account is inactive");       return;     }     super.withdraw(amount);     status = balance >= 25;   }

 

  public void deposit(double amount) {     super.deposit(amount);     status = balance >= 25;   }

 

  public void monthlyProcess() {     int withdrawalsOverLimit = numOfWithdrawals - 4;     if (withdrawalsOverLimit > 0) {       balance -= (1 * withdrawalsOverLimit);     }     super.monthlyProcess();     status = balance >= 25;   }

 

  public boolean getStatus() {     return status;   }

 

public Object getBalance() {     return null; }

 

public String getNumDeposits() {     return null; }

 

public String getNumWithdrawals() {     return null; }

 

public Object getServiceCharge() {     return null; }

 

public boolean isActive() {     return false; } }

 

class Test {     private static SavingsAccount account;

 

    public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         double balance, interestRate, monthlyInterest;         int numDeposits = 0, numWithdrawals = 0, serviceCharge = 0;         System.out.print("Please enter your Account Balance: ");         balance = sc.nextDouble();         System.out.print("Please enter the Annual Interest Rate for the account: ");         interestRate = sc.nextDouble();         monthlyInterest = balance * interestRate / 12.0 / 100.0;         balance = balance + monthlyInterest;         System.out.println("The balance after adding the Monthly Interest: " + balance);         System.out.print("Please enter the amount you want to withdraw: ");         double withdraw = sc.nextDouble();         balance = balance - withdraw;         numWithdrawals += 1;         System.out.println("Balance after withdrawal: " + balance);         System.out.print("Do you want to make any more withdrawals? If yes please enter 1 and if no please enter 0: ");         int moreWithdrawals = sc.nextInt();         while (moreWithdrawals == 1) {            System.out.print("Please enter the amount you want to withdraw: ");            withdraw = sc.nextDouble();            balance = balance - withdraw;            numWithdrawals += 1;            System.out.println("Balance after withdrawal: " + balance);            System.out.print("Do you want to make any more withdrawals? If yes please enter 1 and if no please enter 0: ");            moreWithdrawals = sc.nextInt();         }         System.out.print("Please enter the amount you want to deposit: ");         double deposit = sc.nextDouble();         balance = balance + deposit;         numDeposits += 1;         System.out.println("Balance after depositing: " + balance);         System.out.print("Do you want to make any more deposits? If yes please enter 1 and if no please enter 0: ");         int moreDeposits = sc.nextInt();         while (moreDeposits == 1) {            System.out.print("Please enter the amount you want to deposit: ");            deposit = sc.nextDouble();            balance = balance + deposit;            numDeposits += 1;            System.out.println("Balance after depositing: " + balance);            System.out.print("Do you want to make any more deposits? If yes please enter 1 and if no please enter 0: ");            moreDeposits = sc.nextInt();         }         System.out.println("The total number of deposits made: " + numDeposits);         System.out.println("The total number of withdrawals made: " + numWithdrawals);

 

System.out.printf("The total service charge of the month is %.2f\n", account.getServiceCharge()); if (balance >= 0) {     System.out.println("The savings account is currently active");     } else {     System.out.println("The savings account is currently inactive"); System.out.println("The savings account is currently " + (account.isActive() ? "active" : "inactive"));     } } }   document every line in this code ( dont change anything in it ) header comment also included .

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in
Avatar image
Read by 2 people
Already have an account? Log in

Related questions

Weekly leaderboard

Start filling in the gaps now
Log in