Java Reference
In-Depth Information
4*/
5 public class Investment
6 {
7 /**
8Constructs an Investment object from a starting balance and
9interest rate.
10 @param aBalance the starting balance
11 @param aRate the interest rate in percent
12 */
13 public Investment(double aBalance, double
aRate)
14 {
15 balance = aBalance;
16 rate = aRate;
17 years = 0;
18 }
19
20 /**
21Keeps accumulating interest until a target balance has
22been reached.
23 @param targetBalance the desired balance
24 */
25 public void waitForBalance(double
targetBalance)
26 {
27 while (balance < targetBalance)
28 {
29 years++;
30 double interest = balance * rate /
100;
31 balance = balance + interest;
32 }
33 }
34
35 /**
36Gets the current investment balanace.
37 @return the current balance
38 */
39 public double getBalance()
40 {
41 return balance;
42 }
43
229
230
Search WWH ::




Custom Search