import java.io.*;
import java.util.*;
/******************************************************************************/
/** Candidate main program
 *
 *  This program does the usual open and close of files using the DABUtils methods,
 *  and then it reads the file into an ArrayList and echoes the ArrayList to the
 *  console.
 *
 *  The main difference between this program and the previous program is that in
 *  this program we use in CandidateList3 an ArrayList whose elements are
 *  themselves instances of the Candidate class.  In the previous versions we
 *  read in the data as a complete line of text but did not in fact parse that
 *  text to make any sense of it.  The Candidate class implements a "record"
 *  of multiple "fields" for name, party, and such.  This permits the data to be
 *  searched and manipulated by field directly.
 *
 *  (One could, of course, continue to save the data simply as a single text
 *  string and then implement a search by field by parsing the strings every time.
 *  That, however, is not what is usually done in handling data.)
 *
 * @author Duncan Buell
 *
 * written: 29 March 2008
*/
public class Main3
{
  public static void main(String[] args)
  {
    String inFileName = null;
    String outFileName = null;

    CandidateList3 candidateList = new CandidateList3();
    Scanner console = new Scanner(System.in);
    Scanner inDataFile = null;
    PrintWriter outDataFile = null;

    System.out.printf("Enter input file name: ");
    inFileName = console.next();

    System.out.printf("Enter output file name: ");
    outFileName = console.next();

    System.out.printf("Input file name is: %s%n",inFileName);
    System.out.printf("Output file name is: %s%n",outFileName);

    inDataFile = DABUtils.ScannerOpen(inFileName);
    System.out.printf("Input file '%s' opened, continue%n",inFileName);

    outDataFile = DABUtils.PrintWriterOpen(outFileName);
    System.out.println("Output file '" + outFileName + "' opened, continue");

/******************************************************************************/
/** Read in the candidate
**/
    candidateList.getData(inDataFile);

    System.out.println("File input processed");

/******************************************************************************/
/** Echo the data
**/
    candidateList.echoData(outDataFile);

/******************************************************************************/
/** Print data that matches a search string
**/
    candidateList.printWithMatch(outDataFile,Fields.PARTY,"DEM");

/******************************************************************************/
/** Print data that matches a search string
**/
    candidateList.printWithMatch(outDataFile,Fields.BIRTHPLACE,"South_Carolina");

/******************************************************************************/
/** Close up and go home
**/
    inDataFile.close();

    outDataFile.flush();
    outDataFile.close();
    System.out.printf("File processed, terminate%n");

  } // public static void main(String[] args)

} // public class Main3

