// COBOL Programmers Swing With Java - copyright 2005 Doke, Hardgrave, & Johnson // Chapter 11 - OO Development Issues // Problem Domain Class for CheckingAccount // Interfaces with Data Access class // CheckingAccountPD.java 1 JAN 05 public class CheckingAccountPD extends Account { // instance variable private float minimumBalance; // private scope limited to this class public static void initialize() {CheckingAccountDA.initialize();} // call initialize in Data Access public static void terminate() {CheckingAccountDA.terminate();} // call terminate in Data Access // constructor method public CheckingAccountPD (int newAccountNumber,float newCurrentBalance) { // invoke account constructor to populate account attributes super (newAccountNumber, newCurrentBalance); minimumBalance = newCurrentBalance; // populate checkingAccount attribute } // end constructor // note this is a class method to record a check - we also have an instance method public static CheckingAccountPD recordACheck (int accountNumber, float checkAmount) throws NoAccountFoundException, NSFException { try { // ask Data Access class to get the account instance for us CheckingAccountPD anAccount = CheckingAccountDA.getAccount(accountNumber); anAccount.recordACheck(checkAmount); // if successful, post check for this instance return anAccount; // return the instance reference variable } catch (NoAccountFoundException e) // No Account Found { throw e;} catch (NSFException e) // Not Sufficient Funds { throw e;} } // end class method recordACheck // instance method to post a check to this account public void recordACheck (float checkAmount) throws NSFException { float currentBalance = getCurrentBalance(); if (currentBalance >= checkAmount) // see if sufficient funds { currentBalance = currentBalance - checkAmount; setCurrentBalance(currentBalance); // update the balance in the database CheckingAccountDA.updateAccount(getAccountNumber(),currentBalance); } else { NSFException e = new NSFException("Not Sufficient Funds"); // if not, throw an exception throw e; } // end if } // end instance method recordACheck } // end CheckingAccountPD.java