//An instance of this class represents a simple savings account // Interest is calculated based on the minimum monthly balance // package BankAccounts; public class SavingsAccount extends BankAccount { public static double DEFAULT_INTEREST_RATE = 1.0; //Instance (State) Variables private double interestRate; //Annual % rate private double minimumBalance;//Lowest balance during billing cycle //Constructor // @param initialBalance: initial current balance of this SavingsAccount // @param interestRate: annual interest rate (%) of this SavingsAccount public SavingsAccount(double initialBalance, double interestRate) { super(initialBalance); this.interestRate = interestRate < DEFAULT_INTEREST_RATE ? DEFAULT_INTEREST_RATE : interestRate ; this.minimumBalance = initialBalance; } //Constructor // @param initialBalance: initial current balance of this SavingsAccount public SavingsAccount(double initialBalance) { this(initialBalance, DEFAULT_INTEREST_RATE); } //Accessor public double getInterestRate() { return this.interestRate; } //Accessor public double getMinimumBalance() { return this.minimumBalance; } //Override public String toString() { return super.toString() + " Interest Rate: " + this.interestRate + "%/An." + " Minimum Balance $" + this.minimumBalance ; } //Override public boolean equals(Object other) { if (!super.equals(other)) return false; SavingsAccount that = (SavingsAccount)other; return this.interestRate == that.interestRate && this.minimumBalance == that.minimumBalance; } //Override public void withdraw(double amount) { super.withdraw(amount); if (this.getCurrentBalance() < this.minimumBalance) this.minimumBalance = this.getCurrentBalance(); } //Mutator public void addInterest() { double interest = this.minimumBalance * this.interestRate / 100 / 12; this.credit(interest); } //Mutator public void endOfCycleProcessing() { this.addInterest(); this.minimumBalance = this.getCurrentBalance(); } }