/** * A SavingsAccount is a BankAccount that credits interest to the account * if the balance is above some minimum. */ public class SavingsAccount extends BankAccount { // instance variables private double interestRate; // interest rate; 0.05 means 5% private double minBalance; // minimum account balance to receive interest /** * Construct a new SavingsAccount with the given name, number, * initial balance, interest rate and minimum balance. pre: name!=null */ public SavingsAccount(String name, int number, double initialBalance, double interestRate, double minBalance) { super(name, number, initialBalance); this.interestRate = interestRate; this.minBalance = minBalance; } /** * Credit interest if current account balance is sufficient */ public void creditInterest() { if (this.getBalance() >= this.minBalance) { this.deposit(this.getBalance() * interestRate); } } /** return this SavingsAccount's current interest rate */ public double getInterest() { return this.interestRate; } /** set the interest rate for this SavingsAccount */ public void setInterestRate(double newRate) { this.interestRate = newRate; } /** Return a string representation of this SavingsAccount */ public String toString() { return "SavingsAccount[" + this.getName() + ", " + this.getNumber() + ", " + this.getBalance() + "]"; } }