01: /**
02:    An account that earns interest at a fixed rate.
03: */
04: public class SavingsAccount extends BankAccount
05: {  
06:    /**
07:       Constructs a bank account with a given interest rate.
08:       @param rate the interest rate
09:    */
10:    public SavingsAccount(double rate) 
11:    {  
12:       interestRate = rate;
13:    }
14: 
15:    /**
16:       Adds the earned interest to the account balance.
17:    */
18:    public void addInterest() 
19:    {  
20:       double interest = getBalance() * interestRate / 100;
21:       deposit(interest); 
22:    }
23: 
24:    private double interestRate;
25: }