A good answer might be:

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 calculated 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;

    rate = -0.001;  // This is about to be increased to zero
 
    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 9:

Mentally copy and paste sections of code so that the program is complete.