Higher Interest

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:

Absolutely NOT! That's 80 years without chocolate-chip cookies!

Higher Interest

We obviously need to find a bank with an interest rate higher than five percent. Say that you are willing to wait 40 years for your million dollars. How high must the interest rate be?

One way to answer this question is to try out various interest rates until you find one that works. Here is a program that does that:

import java.util.Scanner;

class DollarsAfterForty
{

  public static void main( String[] args ) 
  {
    double dollars = 1000.00 ;
    double rate;
    int    year =  1 ;     

    // get the interest rate from the user
    Scanner scan = new Scanner( System.in );
    System.out.print("Enter the interest rate in percent: "); 
    rate = scan.nextDouble()/100.0 ;
 
    while (  year <=  )
    {
      // add another year's interest
      dollars =  dollars + dollars *  ; 

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

      year    =  year + 1 ;
    }

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

}

This program does NOT use a result-controlled loop. It uses a counting loop because the counter, year, is used to control the loop.

QUESTION 7:

Fill in the blanks to complete the program.