Exemplo n.º 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;
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Greeting the client
  *
  * @param b - BankClient
  */
 private void receiveClient(BankClient b) {
   AlertLog.getInstance().logMessage(AlertTag.BANK_TELLER, name, "Recieving new client");
   AlertLog.getInstance()
       .logMessage(AlertTag.BANK_TELLER, name, "Hello " + b + ", how may I help you.");
   b.msgMayIHelpYou();
   state = requestState.pending;
 }
Exemplo n.º 3
0
 /**
  * Opens new account
  *
  * @param b - BankClient
  */
 private void openAccount(BankClient b) {
   Account a = new Account(b, 0);
   AlertLog.getInstance()
       .logMessage(AlertTag.BANK_TELLER, name, "New bank account has been opened for " + b);
   Database.INSTANCE.addToDatabase(a);
   b.msgAccountOpened(a);
   state = requestState.notBeingHelped;
 }
Exemplo n.º 4
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;
     }
   }
 }