Million Dollar Program

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:

A long time.

Million Dollar Program

Here is the start on a program that calculates how long it will take:

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

    while ( dollars < 1000000.00 ) // A result-terminated loop
    {
      // add another year's interest

      dollars = ;

      year    = ;
    }

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

}

The value of the bank account, dollars keeps building up until the goal has been reached or exceeded.

QUESTION 3:

Fill in the blanks to complete the program.