Java Reference
In-Depth Information
for (rate = 5; years-- > 0;
System.out.println(balance))
. . . // Bad taste
We won't even begin to decipher what that might mean. You should stick with for
loops that initialize, test, and update a single variable.
ch06/invest2/Investment.java
1 /**
2A class to monitor the growth of an investment that
3accumulates interest at a fixed annual rate.
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++;
Search WWH ::




Custom Search