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

Use the Account class that you created in your previous assignment to model a Ba

ID: 667535 • Letter: U

Question

Use the Account class that you created in your previous assignment to model a Bank account. Create two subclasses for Checking and Savings account that extend your Account class from previous assignment. Implement the following in these 2 subclasses:

A Checking account has an overdraft limit (of $5,000), but a Savings account cannot

be overdrawn. Override the withdraw method in these subclasses to take care of the

overdraft restrictions.

All data and methods are inherited from Account class.

Create constructors for both Checking and Savings account. These constructors

should invoke the constructors of their superclass

Change the deposit method in Account class. Create two overloaded deposit methods in Account class such that one of them takes an integer value as the input parameter and the second one takes a double value as the input parameter.

Write a test program (class named TestAccount) that does the following:

a) Creates 2 objects - a Saving Account and a Checking Account. Get user inputs for

account information that is needed to create these 2 objects.

b) Get user input for an amount to be withdrawn from the Checking Account (for example, $2,500) and an amount to be deposited to the Checking Account (for example, $3,000). Make sure the overdraft restrictions work.

c) Similarly, withdraw and deposit from and into the Saving Account also.

d) Finally, print the account information for both the Checking and Saving accounts (i.e., print the current balance (after withdrawal and deposit), the monthly interest,

and the date when these two accounts were created).

Recap of Account class:

Account class has the following data and behavior

An integer data field – accountId, i.e., the account id (default value is 0).

A double data field – balance that stores the current balance for the account (default value

is 0).

A double data field - annualInterestRate (default value is 0).

A Date data field - dateCreated that stores the date when the account was created.

A no-arg constructor that creates a default account.

A 3-arg constructor that creates an account using a specified account ID, balance, and

annual interest rate.

The accessor(get) and mutator(set) methods for accountId, balance, annualInterestRate.

The accessor(get) method for dateCreated.

A method named getMonthlyInterest() that returns the monthly interest.

A method named withdraw that withdraws a specified amount from the account.

A method named deposit that deposits a specified amount to the account.

Explanation / Answer

working java code

import javax.swing.JOptionPane;
   import java.util.Date;

   public class Account {

      private int id = 0;
      private double balance = 0;
      private double annualInterestRate = 0;
      private double withdraw = 0;
      private double deposite = 0;
      private double total = 0;
      private double monthly = 0;
      private Date date = new Date();
    
      public Account() {
      }
    
      public Account(int id, double balance, double annualInterestRate){
         this.id = id;
         this.balance = balance;
         this.annualInterestRate = annualInterestRate;
      }
          
      public int getId() {
    
         return this.id;
      }
   
      public double getBalance() {
      
         return this.balance;
      }
       
      public double getAnnualInterestRate() {
      
         return this.annualInterestRate;
      }
   
      public java.util.Date getDate() {
    
         return this.date;    
      }

      public String toString() {
         return "Banking Account Information "
            + " Your Customer ID # " + id
            + " Starting Balnce $" + balance
            + " Annual Interest Rate " + annualInterestRate + "%"
            + " Withdraw Amount $" + withdraw
            + " Deposite Amount $" + deposite
            + " Subtotal $" + total
            + " Monthly Interest $"
            + Math.round(monthly * 100.0)/100.0
            + " " + " " + "As of " + date;
      }
   }

   class Checking extends Account{
       public Checking(){
    super();
    //other initialization
}

        double overdraftLimit = -5000;

        public void withdraw(double w) {
            if (balance - w < overdraftLimit)
                    System.out.println("You can't overdraft more than $5000.");
            else
                balance = balance - w;
        }  
    }

class Savings extends Account{
        double overdraftLimit = 0;
       public Savings(){
    super();
    //other initialization
}

        public void withdraw (double w) {
            if (balance - w < overdraftLimit)
                    System.out.println("You don't have enough money");
            else
                balance = balance - w;
        }
    }