home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / JAVA / NOTES / SOURCE / intrest1.jav < prev    next >
Text File  |  1996-12-20  |  1KB  |  48 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 Interest1Console extends ConsoleApplet {
  13.  
  14.    public void init() {
  15.       title = "Sample program \"Interest1\"";
  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 one year.  The interest and
  25.         the value of the investment after one year are
  26.         printed to standard output.
  27.      */
  28.  
  29.  
  30.       double principal = 17000;  // the value of the investment
  31.       double rate = 0.07;        // the annual interest rate
  32.       double interest;           // interest earned in one year
  33.       
  34.       interest = principal * rate;   // compute the interest
  35.       
  36.       principal = principal + interest;
  37.             // compute value of investment after one year, with interest
  38.             // (Note: The new value replaces the old value of pricipal.)
  39.             
  40.       console.put("The interest earned is $");
  41.       console.putln(interest);
  42.       console.put("The value of the investment after one year is $");
  43.       console.putln(principal);
  44.  
  45.    }
  46.  
  47. }
  48.