Exemplo n.º 1
0
  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);
    }
  }