Exemple #1
0
 private void spend() {
   String amountStr =
       JOptionPane.showInputDialog(
           this, "Input an amount to spend:", "Spend", JOptionPane.QUESTION_MESSAGE);
   if (amountStr == null) {
     return;
   }
   String accountNumberStr =
       JOptionPane.showInputDialog(
           this,
           "To what account number? (blank is allowed)",
           "Spend",
           JOptionPane.QUESTION_MESSAGE);
   if (accountNumberStr == null) {
     return;
   }
   try {
     BigDecimal amount = FORMATTER.stringToValue(amountStr);
     Account target;
     if (accountNumberStr.isEmpty()) {
       target = null;
     } else {
       int accountNumber = new IntegerFormatter().stringToValue(accountNumberStr);
       target = null;
       for (User user : Bank.getInstance().getUsers()) {
         for (Account account : user.getAccounts()) {
           if (account.getAccountNumber() == accountNumber) {
             target = account;
           }
         }
       }
     }
     if (target != null
         && (target.getType().isLoan() && target.getBalance().negate().compareTo(amount) < 0)) {
       throw new InvalidInputException(
           accountNumberStr, "account does not exist or cannot accept this deposit");
     }
     account.withdraw(amount);
     if (target != null) {
       target.deposit(amount);
     }
     controller.updateBankDisplay();
   } catch (ParseException px) {
     controller.handleException(this, px);
   } catch (InvalidInputException iix) {
     controller.handleException(this, iix);
   } catch (InsufficientFundsException ifx) {
     controller.handleException(this, ifx);
   }
 }
Exemple #2
0
 private void transfer() {
   String amountStr =
       JOptionPane.showInputDialog(
           this, "Input an amount to transfer:", "Transfer", JOptionPane.QUESTION_MESSAGE);
   if (amountStr == null) {
     return;
   }
   try {
     BigDecimal amount = FORMATTER.stringToValue(amountStr);
     Set<Account> accounts = new HashSet<Account>(controller.getCurrentUser().getAccounts());
     Iterator<Account> iterator = accounts.iterator();
     while (iterator.hasNext()) {
       Account account = iterator.next();
       if (account.getType().isLoan() && account.getBalance().negate().compareTo(amount) < 0) {
         iterator.remove();
       }
     }
     if (!accounts.isEmpty()) {
       Account account =
           (Account)
               JOptionPane.showInputDialog(
                   this,
                   "Choose an account:",
                   "Transfer",
                   JOptionPane.QUESTION_MESSAGE,
                   null,
                   accounts.toArray(),
                   accounts.iterator().next());
       if (account != null) {
         this.account.withdraw(amount);
         account.deposit(amount);
         controller.updateBankDisplay();
       }
     } else {
       JOptionPane.showMessageDialog(
           this,
           "No accounts can accept that balance.",
           "Transfer failed",
           JOptionPane.ERROR_MESSAGE);
       return;
     }
   } catch (ParseException px) {
     controller.handleException(this, px);
   } catch (InvalidInputException iix) {
     controller.handleException(this, iix);
   } catch (InsufficientFundsException ifx) {
     controller.handleException(this, ifx);
   }
 }
Exemple #3
0
  private void flag() {
    Set<Transaction.FraudStatus> permittedFlags = EnumSet.allOf(Transaction.FraudStatus.class);
    if (controller.getCurrentUser().getRole() != User.Role.AUDITOR) {
      permittedFlags.remove(Transaction.FraudStatus.REVERSED);
    }

    Transaction.FraudStatus status =
        (Transaction.FraudStatus)
            JOptionPane.showInputDialog(
                this,
                "Flag as:",
                "Flag",
                JOptionPane.QUESTION_MESSAGE,
                null,
                permittedFlags.toArray(),
                Transaction.FraudStatus.NOT_FLAGGED);
    if (status == null) {
      return;
    }
    try {
      Transaction transaction = account.getHistory().get(historyTable.getSelectedRow());
      transaction.setFraudStatus(status, account);
      update();
    } catch (InvalidInputException iix) {
      controller.handleException(this, iix);
    } catch (InsufficientFundsException ifx) {
      controller.handleException(this, ifx);
    }
  }