Slighly Less Gloomy

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

dollars = dollars + 1000 ;

Slighly Less Gloomy

Here is the completed program:

class MillionDollarYears
{
  public static void main( String[] args )
  {
    double dollars = 1000.00 ;
    int    year = 0;     

    while ( dollars < 1000000.00 )
    {
      // add another year's interest
      dollars =  dollars + dollars*0.05 ; 

      // add in this year's contribution
      dollars = dollars + 1000 ;

      year    =  year + 1 ;
    }

    System.out.println("It took " + year + " years to reach your goal.");
  }

}

And here is its output:

C:/Notes/chap19>java  MillionDollarYears
It took 80 years to reach your goal.

QUESTION 6:

Now it only takes 80 years to reach one million dollars. This is a considerable improvement. Can you wait that long?