home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-20 | 1.1 KB | 46 lines |
- // BankAccount - a general bank account class
- public class BankAccount
- {
- private static int m_AIds = 0;
-
- // id - this is the account id
- private int m_nAccountId;
-
- // balance - the current account's balance
- private double m_dBalance;
-
- // constructor - open account with a balance
- BankAccount(double dInitialBalance)
- {
- m_dBalance = dInitialBalance;
- m_nAccountId = ++m_AIds;
- }
-
- // Id - return the account id
- public int Id()
- {
- return m_nAccountId;
- }
-
- // Balance
- public double Balance()
- {
- return ((int)(m_dBalance * 100.0 + 0.5)) / 100.0;
- }
-
- // Withdrawal - make a withdrawal
- public void Withdrawal(double dAmount)
- throws InsufficientFundsException
- {
- // if there's insufficient funds on hand...
- if (m_dBalance < dAmount)
- {
- // ...throw an exception
- throw new InsufficientFundsException(this, dAmount);
- }
-
- // otherwise, post the debit
- m_dBalance -= dAmount;
- }
- }
-