1 /**
2 An account that earns interest at a fixed rate.
3 */
4 public class SavingsAccount extends BankAccount
5 {
6 private double interestRate;
7
8 /**
9 Constructs a bank account with a given interest rate.
10 @param rate the interest rate
11 */
12 public SavingsAccount(double rate)
13 {
14 interestRate = rate;
15 }
16
17 /**
18 Adds the earned interest to the account balance.
19 */
20 public void addInterest()
21 {
22 double interest = getBalance() * interestRate / 100;
23 deposit(interest);
24 }
25 }