/* * AccountDemo.java * * Created on March 6, 2002, 1:14 PM */ import SavitchIn; /** * * @author Mike Redmond * @version 1 */ public class AccountDemo { // named constants public static final double SALARY = 1000; public static final int MONTHS = 5; /** Creates new AccountDemo */ public AccountDemo() { } /** * Simulate monthly earnings and bill paying * @param args the command line arguments */ public static void main (String args[]) { // create an account full of info for demo Account myAcct = new Account(); myAcct.setAcctNum("111111"); myAcct.setPIN("3129"); myAcct.setBal(SALARY); double currBill = 0; boolean haveMoney = true; // just simulate some months for (int month = 1; month <= MONTHS; month++) { currBill = 0; haveMoney = true; // show balance System.out.println("Status at start of month " + month + " is: " + myAcct.toString() ); // loop through all the bills until user indicates no more // bills this month or account cannot pay latest bill while ((currBill >= 0) && haveMoney ) { System.out.println("How much is the next bill? (enter negative amount to quit)"); currBill = SavitchIn.readLineDouble(); // try to pay the bill if (currBill > 0) { haveMoney = myAcct.withdraw(currBill); System.out.println("Status after paying bill is: " + myAcct.toString() ); } // NOTE - if user enters negative amount - this will also // exit loop } // now next month's deposit // simplification here - unpaid bills are forgotten !! // don't deposit when ending the simulation if (month < MONTHS) { myAcct.deposit(SALARY); } } // end for loop // show balance System.out.println("Status at end of period is: " + myAcct.toString() ); } }