home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-20 | 1.7 KB | 50 lines |
- // App1_4 - test out the BankAcount class.
- // the program expects two inputs: the monthly
- // deposit and the interest rate, as in App1_4 100 8
- // meaning $100 per month at 8% interest (to keep
- // things simple, both are assumed to be integers.)
- // The program calculate the bank balance at the end
- // of each month for 10 years.
- import java.io.*;
-
- public class App1_4
- {
- public static void main(String args[])
- {
- // first argument is the deposit per month
- double dPerMonth = (double)Integer.parseInt(args[0]);
-
- // second argument is the interest rate
- double dInterest = (double)Integer.parseInt(args[1]);
-
- // now set the interest rate
- BankAccount.Rate(dInterest);
-
- // create a BankAccount object
- BankAccount baMyAccount = new BankAccount();
-
- // Make a deposit each month and
- // watch my account grow for 10 years!
- System.out.println("Depositing " +
- dPerMonth +
- " per month at " +
- BankAccount.Rate() +
- " per cent interest");
- System.out.println("Watch my account grow!");
- for (int nYear = 0; nYear < 10; nYear++)
- {
- System.out.print(nYear + " - ");
- for (int nMonth = 0; nMonth < 12; nMonth++)
- {
- // make my deposit
- baMyAccount.Deposit(dPerMonth);
-
- // now take monthly fees and interest
- baMyAccount.Monthly();
- System.out.print(baMyAccount.Balance() + ", ");
- }
- System.out.println();
- }
- }
- }
-