Example #1
0
 /**
  * Processes a withdrawal. If there is enough money, withdraws that amount. If not, just quits
  * with an error message.
  *
  * @param b - BankClient
  */
 private void processWithdrawal(BankClient b) {
   for (Account a : Accounts) {
     if (a.client == b) {
       if (transactionAmount > a.amount) {
         AlertLog.getInstance()
             .logMessage(
                 AlertTag.BANK_TELLER,
                 name,
                 "Error: Attempted to withdraw more money than is available in account.");
         b.msgTransactionCompleted(0);
       } else if (transactionAmount <= a.amount) {
         a.amount = a.amount - transactionAmount;
         AlertLog.getInstance()
             .logMessage(
                 AlertTag.BANK_TELLER,
                 name,
                 "$" + transactionAmount + " has been withdrawn from the account.");
         b.msgTransactionCompleted(transactionAmount);
       }
       state = requestState.none;
       announcer.msgTransactionComplete(LineNum, this, b);
       myClient = null;
     }
   }
 }
Example #2
0
 /**
  * Processes a deposit. If the account exists, deposits the asked amount into the account.
  *
  * @param b - BankClient
  */
 private void processDeposit(BankClient b) {
   AlertLog.getInstance().logMessage(AlertTag.BANK_TELLER, name, "Ok, hold on.");
   for (Account a : Accounts) {
     if (a.client == b) {
       a.amount = a.amount + transactionAmount;
       AlertLog.getInstance()
           .logMessage(
               AlertTag.BANK_TELLER,
               name,
               "$" + transactionAmount + " has been deposited into the account.");
       b.msgTransactionCompleted(transactionAmount - (2 * transactionAmount));
       state = requestState.none;
       announcer.msgTransactionComplete(LineNum, this, b);
       myClient = null;
     }
   }
 }