import java.math.*; /** This class represents savings accounts. It implements state and behavior that define how a savings account differs from a general bank account. */ public class SavingsAccount extends BankAccount { /** Holds the string identifying the type of all savings accounts. */ private static final String ACCOUNT_TYPE = "S"; /** Holds the interest rate "per period" paid on all savings accounts. */ private static double interestRate; /** Return the interest rate. */ public static double getInterestRate() { return interestRate; } /** Set the interest rate. */ public static void setInterestRate(double rate) { interestRate = rate; } /** Create a new empty savings account. Note that the superclass constructor is also executed. */ SavingsAccount() { } /** Return the account type string. */ public String getAccountType() { return ACCOUNT_TYPE; } /** Return the maximum withdrawal amount. Withdrawals may be made only up to the current balance. */ public BigDecimal getWithdrawalLimit() { return getBalance(); } /** Post the interest for this period. Compute the interest amount and add it to the current balance. */ public void postInterest() { double interest = getBalance().doubleValue() * getInterestRate(); setBalance(getBalance().add(new BigDecimal(interest))); } }