home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap03 / BankAccount / App1_3.java < prev    next >
Encoding:
Java Source  |  1996-06-19  |  1.8 KB  |  51 lines

  1. // App1_3 - test out the BankAcount class
  2. //          the program expects two inputs: the monthly
  3. //          deposit and the interest rate, as in:
  4. //          App1_3 100 8
  5. //          meaning $100 per month at 8% interest (to keep
  6. //          things simple, both are assumed to be integers.)
  7. //          The program calculate the bank balance at the end
  8. //          of each month for ten years.
  9. import java.io.*;   // this includes the println() function
  10.  
  11. public class App1_3
  12. {
  13.     public static void main(String args[])
  14.     {
  15.         // first argument is the deposit per month
  16.         double dPerMonth = (double)Integer.parseInt(args[0]);
  17.  
  18.         // second argument is the interest rate
  19.         double dInterest = (double)Integer.parseInt(args[1]);
  20.  
  21.         // create a BankAccount object
  22.         BankAccount baMyAccount = new BankAccount();
  23.  
  24.         // set the interest rate
  25.         baMyAccount.SetRate(dInterest);
  26.  
  27.         // Make a deposit each month and
  28.         // watch my account grow for 10 years!
  29.         System.out.println("Depositing " +
  30.                            dPerMonth +
  31.                            " per month at " +
  32.                            baMyAccount.CurrentRate() +
  33.                            " per cent interest");
  34.         System.out.println("Watch my account grow!");
  35.         for (int nYear = 0; nYear < 10; nYear++)
  36.         {
  37.             System.out.print(nYear + " - ");
  38.             for (int nMonth = 0; nMonth < 12; nMonth++)
  39.             {
  40.                 // make my deposit
  41.                 baMyAccount.Deposit(dPerMonth);
  42.  
  43.                 // now take monthly fees and interest
  44.                 baMyAccount.Monthly();
  45.                 System.out.print(baMyAccount.Balance() + ", ");
  46.             }
  47.             System.out.println();
  48.         }
  49.     }
  50. }
  51.