public class Account
1: // Account.java
2: // Represents a bank account
3:
4: public class Account
5: {
6: private int accountNumber; // account number
7: private int pin; // PIN for authentication
8: private double availableBalance; // funds available for withdrawal
9: private double totalBalance; // funds available + pending deposits
10:
11: // Account constructor initializes attributes
12: public Account( int theAccountNumber, int thePIN,
13: double theAvailableBalance, double theTotalBalance )
14: {
15: accountNumber = theAccountNumber;
16: pin = thePIN;
17: availableBalance = theAvailableBalance;
18: totalBalance = theTotalBalance;
19: } // end Account constructor
20:
21: // determines whether a user-specified PIN matches PIN in Account
22: public boolean validatePIN( int userPIN )
23: {
24: if ( userPIN == pin )
25: return true;
26: else
27: return false;
28: } // end method validatePIN
29:
30: // returns available balance
31: public double getAvailableBalance()
32: {
33: return availableBalance;
34: } // end getAvailableBalance
35:
36: // returns the total balance
37: public double getTotalBalance()
38: {
39: return totalBalance;
40: } // end method getTotalBalance
41:
42: // credits an amount to the account
43: public void credit( double amount )
44: {
45: totalBalance += amount; // add to total balance
46: } // end method credit
47:
48: // debits an amount from the account
49: public void debit( double amount )
50: {
51: availableBalance -= amount; // subtract from available balance
52: totalBalance -= amount; // subtract from total balance
53: } // end method debit
54:
55: // returns account number
56: public int getAccountNumber()
57: {
58: return accountNumber;
59: } // end method getAccountNumber
60: } // end class Account
61:
62:
63: /**************************************************************************
64: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
65: * Pearson Education, Inc. All Rights Reserved. *
66: * *
67: * DISCLAIMER: The authors and publisher of this book have used their *
68: * best efforts in preparing the book. These efforts include the *
69: * development, research, and testing of the theories and programs *
70: * to determine their effectiveness. The authors and publisher make *
71: * no warranty of any kind, expressed or implied, with regard to these *
72: * programs or to the documentation contained in these books. The authors *
73: * and publisher shall not be liable in any event for incidental or *
74: * consequential damages in connection with, or arising out of, the *
75: * furnishing, performance, or use of these programs. *
76: *************************************************************************/