go to previous page   go to home page   go to next page hear noise

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. It asks for an interest rate, then calculates how much money will be in the account after 40 years.

This program does NOT use a result-controlled loop. It uses a counting loop because the counter, year, is used to control the loop and is incremented until it reaches a limit.

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 ;
 
    // Calculate how much money is in the account after 40 years
    
    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" );
  }

}

QUESTION 7:

Fill in the blanks to complete the program.