01: /**
02:    An account that earns interest at a fixed rate.
03: */
04: publicclassSavingsAccountextendsBankAccount
05: {
06: /**
07:       Constructs a bank account with a given interest rate.
08:       @param rate the interest rate
09:    */
10: publicSavingsAccount(doublerate)
11: {
12: interestRate=rate;
13: }
14: 
15: /**
16:       Adds the earned interest to the account balance.
17:    */
18: publicvoidaddInterest()
19: {
20: doubleinterest=getBalance()*interestRate/100;
21: deposit(interest);
22: }
23: 
24: privatedoubleinterestRate;
25: }
 
0 Comments