home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / JAVA / NOTES / SOURCE / intrest2.jav < prev    next >
Text File  |  1996-12-20  |  1KB  |  47 lines

  1.  
  2. /* Simulation of console-I/O program Interest2,
  3.    using ConsoleApplet as a basis.  See the file
  4.    ConsoleApplet.java for more information.
  5.    
  6.    David Eck
  7.    eck@hws.edu
  8.    
  9.    August 2, 1996
  10. */
  11.  
  12. public class Interest2Console extends ConsoleApplet {
  13.  
  14.    public void init() {
  15.       title = "Sample program \"Interest2\"";
  16.       super.init();
  17.    }
  18.  
  19.    protected void program() {
  20.  
  21.       /*
  22.         Program computes the amount of interest that is
  23.         earned on $17,000 invested at an interest
  24.         rate of 0.07 for 5 years.  The value of
  25.         the investment at the end of each year
  26.         is printed to standard output.
  27.       */
  28.  
  29.       double principal = 17000;  // the initial value of the investment
  30.       double rate = 0.07;        // the annual interest rate
  31.       
  32.       int years = 0;  // counts the number of years tha have passed
  33.       
  34.       while (years < 5) {
  35.          double interest = principal * rate;   // compute this year's interest
  36.          principal = principal + interest;     // add it to principal
  37.          years = years + 1;    // count the current year.
  38.          console.put("The value of the investment after ");
  39.          console.put(years);
  40.          console.put(" years is $");
  41.          console.putln(principal);
  42.       } // end of while loop
  43.    
  44.    }
  45.  
  46. }
  47.