import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; import javax.swing.JOptionPane; /* * BankAccountExercise.java * * Created on October 5, 2005, 4:28 PM * * Author: Bill Kraynek */ /** * * @author Bill Kraynek */ public class BankAccountExercise { /** Creates a new instance of BankAccountExercise */ public BankAccountExercise() throws Exception { ArrayList accounts = new ArrayList(); Scanner fileScanner = new Scanner(new File("bankData.txt")); while( true ) { // check to see if any more input lines if( !fileScanner.hasNext() ) break; // get the next line from the file String nextLine = fileScanner.nextLine(); // construct a Scanner object for the next line // get the name from the line and construct a BankAccount object from the name // check to see if an account with that name is in the ArrayList // if it is not in the ArrayList add it to the ArrayList // get the transaction code and amount from the line and process the transaction }// end while JOptionPane.showMessageDialog(null,accounts); JOptionPane.showMessageDialog(null,accounts); Collections.sort(accounts, new CompareBalances()); JOptionPane.showMessageDialog(null,accounts); } /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { new BankAccountExercise(); } class CompareBalances implements Comparator { public int compare(BankAccount left, BankAccount right) { // your code goes here replacing the return 0 statement return 0; } } }