Answer:

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

Pasting in the Dollars Calculation

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

year    =  1 ;     
dollars = initialAmount;              // initialize the loop correctly
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:

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" );
  }

}

To complete the program you will have to nest one loop inside the other.

QUESTION 10:

Copy and paste sections of code.