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

create two subclasses for checking and saving accounts. a checking account has a

ID: 3623886 • Letter: C

Question

create two subclasses for checking and saving accounts. a checking account has an overdraft limit, but a saving account cannot be overdrawn.

The Account class i wrote:

import java.util.Date;
public class Account
{
private int id = 0;
private double balance = 0;
private double annualInterestRate = 0;
private Date dateCreated;

Account()
{
id=0;
balance=0;
annualInterestRate=0;
dateCreated = new Date();

}
Account(int newId,double newBalance)
{
id = newId;
balance= newBalance;
annualInterestRate=0;
dateCreated = new Date();
}
public int getId()
{
return id;
}
public Date getDateCreated()
{
return dateCreated;
}
public double getBalance()
{
return balance;
}
public double getAnnualInterestRate()
{
return annualInterestRate;
}
public void setId(int idPos)
{
id = idPos;
}
public void setBalance(double balancePos)
{
balance = balancePos;
}
public void setAnnualInterestRate(double annualInterestRatePos)
{
annualInterestRate = annualInterestRatePos;
}


public double getMonthlyInterestRate()
{
return annualInterestRate;
}
public double withdraw(double amount)
{

balance=balance-amount;
return balance;
}
public double deposit(double amount)
{
balance=balance + amount ;
return balance;
}


}
thank you

Explanation / Answer

public class CheckingAccount extends Account
{ public CheckingAccount(int 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);
   }

   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 = 3;
   private static final double TRANSACTION_FEE = 2.0;
}


public class Savings extends Account
{
    double deposit = 0;
     Savings()//double s
    {
        super(s);      
       deposit = s;   
       setdeposit(s);
    }    
public void setdeposit(double d)
     {        if(d > balance)   
               {    
                  System.out.println("Can't deposit a value greater than " + " your balance");      
                 System.exit(0);  
         }       
         else
            {
              deposit = d;   
                 balance += d;
     }
      public double getdeposit()
    {
        return deposit;
    }
      public void print()
      {
           String output = "Deposited " + deposit +   " Savings balance after deposit: " + balance;   
    
          System.out.println(output);
}
}