import javax.swing.JFileChooser;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class ApprovalVoteDriver
{
  public static void main(String[] args)
  { ArrayList ballotList = new ArrayList();

    // Create a file dialog for the user to input the file
    JFileChooser fileInput = new JFileChooser(".");
    int chooserChoice = fileInput.showOpenDialog(null);
    if(chooserChoice == JFileChooser.CANCEL_OPTION)
      System.exit(1);
    File file = fileInput.getSelectedFile();
    BufferedReader in = null;
    try
    { in = new BufferedReader(new FileReader(file));
    }
    catch(FileNotFoundException ex){}

    String str = null;
    try
    { str = in.readLine();
    }
    catch(IOException ex){}

    while(str != null)
    { Set ballot = new HashSet();
      StringTokenizer st = new StringTokenizer(str);
      while(st.hasMoreTokens())
        ballot.add(st.nextToken());
      ballotList.add(ballot);
      try
      { str = in.readLine();
      }
      catch( IOException ex){}
   }

    Iterator itr = ballotList.iterator();
    while(itr.hasNext())
      System.out.println(itr.next());
    System.out.println();

    VoterBallots vb = new VoterBallots(ballotList);

    vb.listVotes();
    System.out.println();

    System.out.println(vb.candidatesWithMost());
  }
}

