Пример #1
0
 public void withdraw() {
   String number = currentAccountNumber();
   if (number != null) {
     String s =
         JOptionPane.showInputDialog(
             this, "Enter amount to draw:", "Draw Money", JOptionPane.QUESTION_MESSAGE);
     if (s != null) {
       try {
         double amount = Double.parseDouble(s);
         Account a = accounts.get(number);
         a.withdraw(amount);
         fld_balance.setText(currencyFormat(a.getBalance()));
       } catch (NumberFormatException e) {
         JOptionPane.showMessageDialog(this, "Illegal Value", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (IllegalArgumentException e) {
         JOptionPane.showMessageDialog(
             this, "Illegal Argument", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (InactiveException e) {
         JOptionPane.showMessageDialog(
             this, "Account is inactive", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (OverdrawException e) {
         JOptionPane.showMessageDialog(
             this, "Account must not be overdrawn", "Error", JOptionPane.ERROR_MESSAGE);
       } catch (Exception e) {
         error(e);
       }
     }
   }
 }
Пример #2
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;
     }
   }
 }
Пример #3
0
  public void transfer() {
    String number = currentAccountNumber();
    if (number != null) {
      try {
        Set<String> s = new HashSet<String>(accounts.keySet());
        s.remove(number);

        TransferDialog trans = new TransferDialog(this, "Transfer Money", number, s);
        Point loc = getLocation();
        trans.setLocation(loc.x + 50, loc.y + 50);
        trans.setModal(true);
        trans.setVisible(true);

        if (!trans.canceled()) {
          if (number.equals(trans.getAccountNumber())) {
            JOptionPane.showMessageDialog(
                this, "Both Accounts are the same!", "Error", JOptionPane.ERROR_MESSAGE);
          } else {
            try {
              double amount = Double.parseDouble(trans.getBalance());
              Account from = accounts.get(number);
              Account to = accounts.get(trans.getAccountNumber());
              bank.transfer(from, to, amount);

              // after transfer adjust value of displayed account
              fld_balance.setText(currencyFormat(from.getBalance()));

              JOptionPane.showMessageDialog(
                  this, "Transfer successfull", "Information", JOptionPane.INFORMATION_MESSAGE);
            } catch (NumberFormatException e) {
              JOptionPane.showMessageDialog(
                  this, "Illegal Balance", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (IllegalArgumentException e) {
              JOptionPane.showMessageDialog(
                  this, "Illegal Argument", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (InactiveException e) {
              JOptionPane.showMessageDialog(
                  this, "At least one account is inactive", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (OverdrawException e) {
              JOptionPane.showMessageDialog(
                  this, "Account must not be overdrawn", "Error", JOptionPane.ERROR_MESSAGE);
            }
          }
        }
      } catch (Exception e) {
        error(e);
      }
    }
  }
Пример #4
0
  public void addAccount() {
    AddAccountDialog addaccount = new AddAccountDialog(this, "Add Account");

    Point loc = getLocation();
    addaccount.setLocation(loc.x + 50, loc.y + 50);
    addaccount.setModal(true);
    addaccount.setVisible(true);

    if (!addaccount.canceled()) {
      String number = null;
      try {
        number = bank.createAccount(addaccount.getOwnerName());
      } catch (Exception e) {
        error(e);
      }

      if (number == null) {
        JOptionPane.showMessageDialog(
            this, "Account could not be created", "Error", JOptionPane.ERROR_MESSAGE);
      } else {
        try {
          Account acc = bank.getAccount(number);
          accounts.put(number, acc);

          String str = addaccount.getBalance().trim();
          double amount;
          if (str.equals("")) amount = 0;
          else amount = Double.parseDouble(str);
          acc.deposit(amount);
        } catch (NumberFormatException e) {
          JOptionPane.showMessageDialog(this, "Illegal Format", "Error", JOptionPane.ERROR_MESSAGE);
        } catch (IllegalArgumentException e) {
          JOptionPane.showMessageDialog(
              this, "Illegal Argument", "Error", JOptionPane.ERROR_MESSAGE);
        } catch (InactiveException e) {
          JOptionPane.showMessageDialog(
              this, "Account is inactive", "Error", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e) {
          error(e);
        }
        ignoreItemChanges = true;
        accountcombo.addItem(number);
        accountcombo.setSelectedItem(number);
        ignoreItemChanges = false;
        refreshDialog();
      }
    }
  }
Пример #5
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;
     }
   }
 }
Пример #6
0
 private void updateCustomerInfo() {
   String nr = currentAccountNumber();
   try {
     if (nr != null) {
       Account a = accounts.get(nr);
       if (a != null) {
         fld_owner.setText(a.getOwner());
         fld_balance.setText(currencyFormat(a.getBalance()));
       } else {
         JOptionPane.showMessageDialog(
             this, "Account not found", "Error", JOptionPane.ERROR_MESSAGE);
         refreshDialog();
       }
     } else {
       fld_owner.setText("");
       fld_balance.setText("");
     }
   } catch (Exception e) {
     error(e);
   }
 }