예제 #1
0
  public static void main(String[] args) {

    Account a1 = new Account();

    System.out.println(
        "Account Number: " + a1.getAccountNumber() + " Account Balance:" + a1.getAccountBalance());

    Account a2 = a1;

    System.out.println(
        "Account Number: " + a2.getAccountNumber() + " Account Balance:" + a2.getAccountBalance());

    a1.deposit(100);

    System.out.println(
        "Account Number: " + a2.getAccountNumber() + " Account Balance:" + a2.getAccountBalance());

    a2 = null;

    System.out.println(
        "Account Number: " + a1.getAccountNumber() + " Account Balance:" + a1.getAccountBalance());

    Account a3 = a1;

    a1 = null;

    a1 = new Account();
    a1.deposit(1000);
    a1.setAccountNumber(11);

    a2 = a1;

    a3 = null;

    a1 = null;

    a2 = null;

    int l = 40;
    int k = 30;
    int j = 50;

    l = k + j;

    System.out.println("L:" + l + " K:" + k + " J:" + j);

    l = j;

    System.out.println("L:" + l + " K:" + k + " J:" + j);

    j = 100;

    System.out.println("L:" + l + " K:" + k + " J:" + j);
  }
예제 #2
0
  @Test
  public void testSaveAccountForReal() {

    try {
      Account account = new Account("54321", "Joe Soap");

      // Now call service method
      bankService.save(account);
      Account newAccount = bankService.getAccount(account.getAccountNumber());
      Assert.assertEquals(account.getAccountNumber(), newAccount.getAccountNumber());
    } catch (BankServiceException e) {
      LOG.error(e.getMessage(), e);
      Assert.fail("Unexpected exception thrown during test: " + e.getMessage());
    }
  }
예제 #3
0
 private Account getAccount(int paramInt) {
   for (Account localAccount : this.accounts) {
     if (localAccount.getAccountNumber() == paramInt) {
       return localAccount;
     }
   }
   return null;
 }
예제 #4
0
 public Account identify(int accountNumber, int pin) {
   Account identifiedAccount = null;
   for (Account account : accounts) {
     if (account.getAccountNumber() == accountNumber && account.getPin() == pin) {
       identifiedAccount = account;
       break;
     }
   }
   return identifiedAccount;
 }
예제 #5
0
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof Account) {
     Account account = (Account) obj;
     if (this.accountNumber.equals(account.getAccountNumber())) {
       return true;
     } else return false;
   }
   return false;
 }
예제 #6
0
  /**
   * Returns an array of the accounts on the system. If no accounts are registered the method
   * returns an empty array.
   *
   * @return all accounts
   */
  public synchronized Account[] getAccounts() {
    if (accounts == null) {
      loadAccounts();
    }

    if ((newAccount != null) && newAccount.getAccountNumber() != -1) {
      accounts.add(newAccount);
      newAccount = null;
    }

    return accounts.toArray(EMPTY_ACCOUNT_ARRAY);
  }
 /*
  * Add a new Account object to the Bank's accounts array
  *
  * @param account A reference to the Account object to be added to the accounts array
  */
 public void addAccount(Account account) {
   // may need something if Account account is null
   // this method would be so much easier using an ArrayList
   if (accountExists(account.getAccountNumber())) {
     System.out.println(
         "An account already exists with that account Number.  Account not added to bank.");
   } else {
     setTotalAccounts(getTotalAccounts() + 1);
     if (getTotalAccounts() > getAccountsArray().length) {
       reallocate();
     }
     this.accounts[getTotalAccounts() - 1] = account;
   }
 }
예제 #8
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);
   }
 }
예제 #9
0
  public static Intent actionHandleNotification(
      Context context, Account account, String initialFolder) {
    Intent intent =
        new Intent(
            Intent.ACTION_VIEW,
            Uri.parse("email://accounts/" + account.getAccountNumber()),
            context,
            FolderList.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
    intent.putExtra(EXTRA_FROM_NOTIFICATION, true);

    if (initialFolder != null) {
      intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
    }
    return intent;
  }
예제 #10
0
 public synchronized void loadAccounts() {
   accounts = new HashMap<String, Account>();
   accountsInOrder = new LinkedList<Account>();
   String accountUuids = getPreferences().getString("accountUuids", null);
   if ((accountUuids != null) && (accountUuids.length() != 0)) {
     String[] uuids = accountUuids.split(",");
     for (String uuid : uuids) {
       Account newAccount = new Account(this, uuid);
       accounts.put(uuid, newAccount);
       accountsInOrder.add(newAccount);
     }
   }
   if ((newAccount != null) && newAccount.getAccountNumber() != -1) {
     accounts.put(newAccount.getUuid(), newAccount);
     accountsInOrder.add(newAccount);
     newAccount = null;
   }
 }
예제 #11
0
  /**
   * Returns an array of the accounts on the system. If no accounts are registered the method
   * returns an empty array.
   *
   * @return all accounts with {@link Account#isAvailable(Context)}
   */
  public synchronized Collection<Account> getAvailableAccounts() {
    if (accounts == null) {
      loadAccounts();
    }

    if ((newAccount != null) && newAccount.getAccountNumber() != -1) {
      accounts.add(newAccount);
      newAccount = null;
    }
    Collection<Account> retval = new ArrayList<Account>(accounts.size());
    for (Account account : accounts) {
      if (account.isAvailable(mContext)) {
        retval.add(account);
      }
    }

    return retval;
  }
예제 #12
0
파일: Account.java 프로젝트: kaskay/java
 public boolean equals(Object obj) {
   Account account = (Account) obj;
   return this.accountNumber.equals(account.getAccountNumber());
 }
예제 #13
0
  public void exportAccount() {

    final Date exportDate = new Date();

    if (account == null || startDate == null || endDate == null || file == null) {
      throw new RuntimeException();
    }

    // force a correct file extension
    final String fileName = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".ofx";

    try (IndentedPrintWriter writer =
        new IndentedPrintWriter(
            new BufferedWriter(
                new OutputStreamWriter(
                    new FileOutputStream(fileName), Charset.forName("windows-1252"))))) {

      indentedWriter = writer;

      // write the required header
      for (String line : OFXHEADER) {
        writer.println(line, indentLevel);
      }
      writer.println();

      // start of data
      writer.println(wrapOpen(OFX), indentLevel++);

      // write sign-on response
      writer.println(wrapOpen(SIGNONMSGSRSV1), indentLevel++);
      writer.println(wrapOpen(SONRS), indentLevel++);
      writer.println(wrapOpen(STATUS), indentLevel++);
      writer.println(wrapOpen(CODE) + "0", indentLevel);
      writer.println(wrapOpen(SEVERITY) + "INFO", indentLevel);
      writer.println(wrapClose(STATUS), --indentLevel);
      writer.println(wrapOpen(DTSERVER) + encodeDate(exportDate), indentLevel);
      writer.println(wrapOpen(LANGUAGE) + "ENG", indentLevel);
      writer.println(wrapClose(SONRS), --indentLevel);
      writer.println(wrapClose(SIGNONMSGSRSV1), --indentLevel);

      writer.println(wrapOpen(getBankingMessageSetAggregate(account)), indentLevel++);
      writer.println(wrapOpen(getResponse(account)), indentLevel++);
      writer.println(wrapOpen(TRNUID) + "1", indentLevel);
      writer.println(wrapOpen(STATUS), indentLevel++);
      writer.println(wrapOpen(CODE) + "0", indentLevel);
      writer.println(wrapOpen(SEVERITY) + "INFO", indentLevel);
      writer.println(wrapClose(STATUS), --indentLevel);

      // begin start of statement response
      writer.println(wrapOpen(getStatementResponse(account)), indentLevel++);
      writer.println(wrapOpen(CURDEF) + account.getCurrencyNode().getSymbol(), indentLevel);

      // write account identification
      writer.println(wrapOpen(getAccountFromAggregate(account)), indentLevel++);

      switch (account.getAccountType()) {
        case INVEST:
        case MUTUAL:
          writer.println(
              wrapOpen(BROKERID),
              indentLevel); //  required for investment accounts, but jGnash does not manage a
                            // broker ID, normally a web URL
          break;
        default:
          writer.println(
              wrapOpen(BANKID) + account.getBankId(), indentLevel); // savings and checking only
          break;
      }

      writer.println(wrapOpen(ACCTID) + account.getAccountNumber(), indentLevel);

      // write the required account type
      switch (account.getAccountType()) {
        case CHECKING:
          writer.println(wrapOpen(ACCTTYPE) + CHECKING, indentLevel);
          break;
        case ASSET:
        case BANK:
        case CASH:
          writer.println(wrapOpen(ACCTTYPE) + SAVINGS, indentLevel);
          break;
        case CREDIT:
        case LIABILITY:
          writer.println(wrapOpen(ACCTTYPE) + CREDITLINE, indentLevel);
          break;
        case SIMPLEINVEST:
          writer.println(wrapOpen(ACCTTYPE) + MONEYMRKT, indentLevel);
          break;
        default:
          break;
      }

      writer.println(wrapClose(getAccountFromAggregate(account)), --indentLevel);

      // begin start of transaction list
      writer.println(wrapOpen(getTransactionList(account)), indentLevel++);
      writer.println(wrapOpen(DTSTART) + encodeDate(startDate), indentLevel);
      writer.println(wrapOpen(DTEND) + encodeDate(endDate), indentLevel);

      // write the transaction list
      if (account.getAccountType() == AccountType.INVEST
          || account.getAccountType() == AccountType.MUTUAL) {
        writeInvestmentTransactions();
      } else {
        writeBankTransactions();
      }

      // end of transaction list
      writer.println(wrapClose(getTransactionList(account)), --indentLevel);

      // write ledger balance
      writer.println(wrapOpen(LEDGERBAL), indentLevel++);
      writer.println(wrapOpen(BALAMT) + account.getBalance(endDate).toPlainString(), indentLevel);
      writer.println(wrapOpen(DTASOF) + encodeDate(exportDate), indentLevel);
      writer.println(wrapClose(LEDGERBAL), --indentLevel);

      // end of statement response
      writer.println(wrapClose(getStatementResponse(account)), --indentLevel);
      writer.println(wrapClose(getResponse(account)), --indentLevel);
      writer.println(wrapClose(getBankingMessageSetAggregate(account)), --indentLevel);

      // finished
      writer.println(wrapClose(OFX), --indentLevel);
    } catch (IOException e) {
      Logger.getLogger(OfxExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
  }
 /**
  * **************************************************************** compares two accounts
  *
  * @return if the first account is before or after the second
  * @param a1, the first account
  * @param a2, the second account ***************************************************************
  */
 @Override
 public int compare(Account a1, Account a2) {
   return a1.getAccountNumber() - a2.getAccountNumber();
 }