/* File: BankTester.java (interactive input version) A test class for the Bank class. Reads data for any number of bank accounts until eof, from the keyboard After reading the data for each account, a BankAccount object is created and added to the bank */ import GregBank.BankAccount; import GregBank.Bank; import java.io.IOException; import java.util.Scanner ; import javax.swing.JOptionPane ; /** A test class for the Bank class. */ public class BankTester { public static void main(String[] args) throws IOException { // create Bank object Bank firstBankOfJava = new Bank() ; // "priming" read String input = JOptionPane.showInputDialog ("Enter first account number and initial balance" + "\n(separated by spaces) (Cancel to quit)") ; while ( input != null ) // while not eof { Scanner scan = new Scanner(input) ; String accountNumber = scan.next() ; double balance = scan.nextDouble() ; // create BankAccount object BankAccount next = new BankAccount(accountNumber, balance) ; // add to list firstBankOfJava.addAccount( next ) ; input = JOptionPane.showInputDialog ("Enter next account number and initial balance" + "\n(separated by spaces) (Cancel to quit)") ; } // here at eof - list has been populated // print the list of accounts firstBankOfJava.printList() ; // get total on deposit, all accounts System.out.println( "\nTotal on deposit in all accounts is $" + + firstBankOfJava.getTotalBalance() ) ; // find number of accounts with balance of at least specified amount input = JOptionPane.showInputDialog ("Find number of accounts with what minimum balance?" ) ; double threshold = Double.parseDouble(input) ; int count = firstBankOfJava.count(threshold) ; System.out.println("\nFound " + count + " accounts with balance of " + "at least $" + threshold) ; // find account with greatest balance BankAccount max = firstBankOfJava.getMaximum() ; if ( max != null ) // there are accounts System.out.println( "\nAccount with number " + max.getAccountNumber() + " has the largest balance ($" + + max.getBalance() + ")" ) ; else System.out.println( "\nSorry, no accounts!" ) ; // search the list for some specific accounts String accountNumber = JOptionPane.showInputDialog ("Enter account number to search for (or Cancel to quit)") ; while ( accountNumber != null ) // while not eof { BankAccount target = firstBankOfJava.find(accountNumber) ; if (target == null) System.out.println("\nNo account with number " + accountNumber) ; else System.out.println("\nAccount with number " + accountNumber + " has balance of $" + target.getBalance() ) ; accountNumber = JOptionPane.showInputDialog ("Enter next account number to search for (or Cancel to quit)") ; } System.exit(0) ; } } /* sample output Account Number Account Balance ============== =============== 1111111 $ 15,000.00 2222222 $ 20,000.00 3333333 $ 12,500.00 4444444 $ 37,000.00 Total on deposit in all accounts is $84500.0 Found 3 accounts with balance of at least $15000.0 Account with number 4444444 has the largest balance ($37000.0) Account with number 2222222 has balance of $20000.0 No account with number 9999999 */