go to previous page   go to home page   go to next page hear noise highlighting

Answer:

The previous program used a loop that iterated 40 times to calculate that.


Copy and Paste the Dollars Calculation

Here is the part from the previous program (slightly modified) that calculates the number of dollars after 40 years:

int year =  1 ;     
dollars = initialAmount;              // initialize the loop
while (  year <= 40 )
{     
  dollars = dollars + dollars*rate  ; // add another year's interest     
  dollars = dollars + 1000 ;          // add in this year's contribution
  year    =  year + 1 ;
}

Here is the skeleton program again:

public class  MillionDollarInterestRate
{

  public static void main( String[] args ) 
  {
    double initialAmount = 1000.00 ;
    double dollars = 0.0;
    double rate = -0.001; // This is about to change
 
    while ( dollars < 1000000 )
    {
       // change to the next rate
       rate = rate + 0.001;

       // compute the dollars after 40 years at the current rate
       


    }

    System.out.println("After 40 years at " + rate*100 
      + " percent interest you will have " + dollars + " dollars" );
  }

}

QUESTION 10:

To complete the program nest one loop inside the other.

Copy and paste sections of code from this web page.


go to previous page   go to home page   go to next page