コード例 #1
0
ファイル: Atm.java プロジェクト: TracyMRohlin/Java-GUI
  public void printAllAccounts(String customerID) {
    // Sorts the customer based on ID, then prints the accounts information

    // change the withdrawal funcitons and deposit functions too
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    Collections.sort(cust, Customer.CompareIDs);
    String searchString = ajf.getCustomerID();

    StringBuilder stringResults = new StringBuilder();
    String header = header();
    stringResults.append(header);
    for (Customer customer : cust) {
      String id = customer.returnID();
      String name = customer.getName().toUpperCase();
      String pin = customer.returnPin();
      if (searchString.equals(id)) {
        ArrayList<Account> accounts = customer.getAccounts();
        if (!accounts.isEmpty()) {
          for (Account account : accounts) {
            if (account.checkActive()) {
              String accountNumber = account.returnNumber();
              double balance = account.returnBalance();
              String balanceAsString = formatter.format(balance);
              String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString);
              stringResults.append(customerInfo);
            }
          }
        }
      }
    }
    String resultsAsString = stringResults.toString();
    ajf.printInfo(resultsAsString);
  }
コード例 #2
0
ファイル: Atm.java プロジェクト: TracyMRohlin/Java-GUI
  public void printHighestBalance() {
    // prints the accounts from highest amount to lowest, with those who have empty accounts last
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    StringBuilder stringResults = new StringBuilder();
    String header = header();
    stringResults.append(header);

    if (!cust.isEmpty()) {
      ArrayList<Account> allAccounts = new ArrayList<Account>();
      ArrayList<Customer> CustomersNoAccounts = new ArrayList<Customer>();
      for (Customer c : cust) {
        ArrayList<Account> accounts = c.getAccounts();
        if (!accounts.isEmpty()) {
          // Concatenates all the accounts together for easy sorting
          allAccounts.addAll(accounts);
        }
        // Adds customers without accounts to a separate list to be printed at the end of all the
        // others
        else {
          CustomersNoAccounts.add(c);
        }
      }
      if (!allAccounts.isEmpty()) {
        Collections.sort(allAccounts, Account.CompareBalances);
        for (Account a : allAccounts) {
          if (a.checkActive()) {
            String id = a.getID();
            String name = a.getName().toUpperCase();
            String pin = a.getPin();
            String accountNumber = a.returnNumber();
            double balance = a.returnBalance();
            String balanceAsString = formatter.format(balance);
            String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString);
            stringResults.append(customerInfo);
          }
        }
      }
      if (!CustomersNoAccounts.isEmpty()) {
        Collections.sort(CustomersNoAccounts, Customer.CompareName);
        for (Customer c : CustomersNoAccounts) {
          String id = c.returnID();
          String name = c.getName().toUpperCase();
          String pin = c.returnPin();
          String noAccounts = String.format("%-20s %-9s %-10s\n", name, id, pin);
          stringResults.append(noAccounts);
        }
      }
      String resultsAsString = stringResults.toString();
      ajf.printInfo(resultsAsString);
    }
  }
コード例 #3
0
ファイル: Atm.java プロジェクト: TracyMRohlin/Java-GUI
  public void printByCustomerName() {
    // Prints the database info by customer's name in ascending order
    Collections.sort(cust, Customer.CompareName);
    ajf.dispose();
    ajf = new AdminRunningFrame(this);

    StringBuilder stringResults = new StringBuilder();
    String header = header();
    stringResults.append(header);

    if (!cust.isEmpty()) {
      for (Customer customer : cust) {
        String id = customer.returnID();
        String name = customer.getName().toUpperCase();
        String pin = customer.returnPin();
        ArrayList<Account> accounts = customer.getAccounts();
        if (!accounts.isEmpty()) {
          for (Account account : accounts) {
            if (account.checkActive()) {
              String accountNumber = account.returnNumber();
              double balance = account.returnBalance();
              String balanceAsString = formatter.format(balance);
              String customerInfo = printAdminInfo(name, id, accountNumber, pin, balanceAsString);
              stringResults.append(customerInfo);
            }
          }

        } else {
          // Still prints customers who have created customer accounts but not set up any
          // checking/savings
          String noAccounts = String.format("%-20s %-9s %-10s\n", name, id, pin);
          stringResults.append(noAccounts);
        }
      }
    }
    String resultsAsString = stringResults.toString();
    ajf.printInfo(resultsAsString);
  }