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 implement some new routines in CandidateList4, like a * simple sorting routine. * * @author Duncan Buell * * written: 29 March 2008 */ public class Main4 { public static void main(String[] args) { String inFileName = null; String outFileName = null; CandidateList4 candidateList = new CandidateList4(); 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"); /******************************************************************************/ /** Sort data by a field, and then print the new list. **/ candidateList.sortData(Fields.BIRTHPLACE); candidateList.echoData(outDataFile); /******************************************************************************/ /** 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 Main4