1  /**
  2     A savings account earns interest on the minimum balance.
  3  */
  4  public class SavingsAccount extends BankAccount
  5  {
  6     private double interestRate;
  7     private double minBalance; 
  8  
  9     /**
 10        Constructs a savings account with a zero balance.
 11     */
 12     public SavingsAccount()
 13     {
 14        interestRate = 0;
 15        minBalance = 0;
 16     }
 17  
 18     /**
 19        Sets the interest rate for this account.
 20        @param rate the monthly interest rate in percent
 21     */
 22     public void setInterestRate(double rate)
 23     {
 24        interestRate = rate;
 25     }
 26  
 27     public void withdraw(double amount)
 28     {
 29        super.withdraw(amount);
 30        double balance = getBalance();
 31        if (balance < minBalance)
 32        {
 33           minBalance = balance;
 34        }
 35     }
 36     
 37     public void monthEnd()
 38     {
 39        double interest = minBalance * interestRate / 100;
 40        deposit(interest);
 41        minBalance = getBalance();
 42     }
 43  }