home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap04 / BankAccount / App1_4.java < prev    next >
Encoding:
Java Source  |  1996-06-20  |  1.7 KB  |  50 lines

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