import java.io.*; import java.util.*; /******************************************************************************/ /** CandidateList2 class for storing and manipulating the ArrayList of data. * In this version, all that we have done is to move the code and data from * the main program in the previous version into instance variables and * methods in this separate class. **/ public class CandidateList2 { private ArrayList theList; /******************************************************************************/ /** Construct a new candidate with the given information. **/ public CandidateList2() { this.theList = new ArrayList(); } /******************************************************************************/ /** * accessor methods **/ // none at present /******************************************************************************/ /** * mutator methods **/ // none at present /******************************************************************************/ /** * general methods **/ /******************************************************************************/ /** * echo the data from the ArrayList **/ public void echoData(PrintWriter outDataFile) { outDataFile.printf("%nThe entire list of candidates is%n"); for(int i = 0; i < theList.size(); ++i) { outDataFile.printf("%2d %s%n",i,theList.get(i).toString()); } } // public void echoData(PrintWriter outDataFile) /******************************************************************************/ /** * get the data line by line and add to the ArrayList **/ public void getData(Scanner inDataFile) { String readString; while(inDataFile.hasNextLine()) { readString = inDataFile.nextLine(); this.theList.add(readString); } // while(inDataFile.hasNextLine()) } // public void getData(Scanner inDataFile) } // public class Candidate extends Object