previous | start | next

File SavingsAccount.java

1 /**
2     An account that earns interest at a fixed rate.
3 */
4 public class SavingsAccount extends BankAccount
5 {  
6    /**
7        Constructs a bank account with a given interest rate
8       @param rate the interest rate
9     */
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 }


previous | start | next