/* * Redmond8.java * * Created on March 19, 2002, 11:31 PM */ /** * * @author mike redmond * @version 1.0 * * Basic ATM with simplifying assumptions - such as only one account in the whole bank */ public class Redmond8 { /** Creates new Redmond8 */ public Redmond8() { } /** * @param args the command line arguments */ public static void main (String args[]) { //RevisedAccount myAcct = new RevisedAccount(); Account myAcct = new Account(); int acct = 0; boolean ok; // set up one initial account System.out.println("Initializing system."); System.out.println("Please enter the account number to be used in this simulation"); String acctNum = SavitchIn.readLine(); myAcct.setAcctNum(acctNum); System.out.println("Please enter the 4 digit PIN to be used in this simulation"); String pin = SavitchIn.readLine(); myAcct.setPIN(pin); System.out.println("Please enter the beginning balance to be used in this simulation"); double bal = SavitchIn.readLineDouble(); // ensure that the balance starts out positive while (bal < 0) { System.out.println("Please enter A POSITIVE beginning balance to be used in this simulation"); bal = SavitchIn.readLineDouble(); } myAcct.setBal(bal); System.out.println("Please enter the interest rate to be used in this simulation (NOTE 2% is written .02)"); double rate = SavitchIn.readLineDouble(); // ensure that the interest rate is reasonable while ((rate < 0) || (rate > .20)) { System.out.println("Please enter a positive interest rate (no larger than .2) to be used in this simulation (NOTE 2% is written .02)"); rate = SavitchIn.readLineDouble(); } myAcct.setIntRate(rate); System.out.println("How many days in this simulation"); int numDays = SavitchIn.readLineInt(); // ensure that the # days is positive while (numDays <= 0) { System.out.println("Please enter A POSITIVE number of days in this simulation"); numDays = SavitchIn.readLineInt(); } System.out.println("In this dummy bank there is only 1 valid account. Work with it:"); System.out.println(" " + myAcct.toString()); // go through all of the days in the simulation // each day - see if anybody is coming // if somebody is coming - after ensuring that they are a valid customer // allow them to do as many transactions as they want to // at the end of the day - pay interest to the account for (int day = 0; day < numDays; day++) { System.out.println("Is anybody banking today?"); char answ = SavitchIn.readLineNonwhiteChar(); // if somebody banking today - check acct num etc then let them bank if ((answ == 'Y') || (answ == 'y')) { // assume not valid until learn otherwise boolean acctOk = false; // ensure that acct num and pin are valid while (acctOk == false) { // ask user for acct info System.out.println("Enter your account number"); String currAcctNum = SavitchIn.readLine(); System.out.println("Enter your PIN"); String currPIN = SavitchIn.readLine(); // ensure that the account number and pin are correct if ((myAcct.getAcctNum().equals(currAcctNum)) && (myAcct.getPin().equals(currPIN)) ) { acctOk = true; } } // end validating while int choice = 0; // let user bank until they indicate that they want to quit while (choice != 4) { System.out.println("Choose:"); System.out.println(" 1) Deposit 2) Withdraw 3) Account Balance 4) Quit"); choice = SavitchIn.readLineInt(); // handle user choice switch (choice) { case 1: // user depositing - make sure they give a valid amount double depositAmt = -1; while ((depositAmt < 1.0) || (depositAmt > 2000)) { System.out.println("Please enter the deposit amount (between 1 and 2000)"); depositAmt = SavitchIn.readLineDouble(); } // actually make the deposit ok = myAcct.deposit(depositAmt); break; // end deposit case 2: // user withdrawing - make sure they give a valid amount double withdrawAmt = -1; while ((withdrawAmt <= 20.0) || (withdrawAmt > 200)) { System.out.println("Please enter the withdraw amount (between 20 and 200)"); withdrawAmt = SavitchIn.readLineDouble(); } // actually make the withdrawal ok = myAcct.withdraw(withdrawAmt); break; // end withdraw case 3: // handle balance inquiry System.out.println("Your Account: "); System.out.println(myAcct.getAcctNum() + " Bal: " + myAcct.getBal()); break; // end account inquiry default: // didn't choose an action needing a response // can do nothing and user will be reprompted for something to do } // end switch } // end while choice } // end if answ //give interest to account at end of day double intPaid = myAcct.payInterest(1); System.out.println("At end of day " + (day+1) + " interest paid: " + intPaid); } // end for // report final results System.out.println("Times up!"); System.out.println("Updated account:"); System.out.println(" " + myAcct.toString()); } }