public class Interest3 {
   
   /*
      This class implements a simple program that
      will compute the amount of interest that is
      earned on an investment over a period of
      5 years.  The initial amount of the investment
      and the interest rate are input by the user.
      The value of the investment at the end of each
      year is output.
   */

   public static void main(String[] args) {
   
       double principal;  // the value of the investment
       double rate;       // the annual interest rate
       
       TextIO.put("Enter the initial investment: ");
       principal = TextIO.getlnDouble();
       
       TextIO.put("Enter the annual interest rate: ");
       rate = TextIO.getlnDouble();
       
       int years = 0;  // counts the number of years that have passed
       
       while (years < 5) {
          double interest = principal * rate;   // compute this year's interest
          principal = principal + interest;     // add it to principal
          years = years + 1;    // count the current year.
          if (years > 1) {
             TextIO.put("The value of the investment after ");
             TextIO.put(years);
             TextIO.put(" years is $");
          }
          else {
             TextIO.put("The value of the investment after 1 year is $");
          }
          TextIO.putln(principal);
       } // end of while loop
       
   } // end of main()
      
} // end of class Interest3

