// Read a list of people from a file, output the list, and then examine it. // Barry Cornelius, 19 June 2000 import java.util. ArrayList; import java.io. BufferedReader; import java.io. FileReader; import java.io. InputStreamReader; import java.io. IOException; import java.util. Iterator; import java.util. List; public class ExamineList { public static void main(final String[] pArgs) throws IOException { if (pArgs.length!=1) { System.out.println("Usage: java ExamineList datafile"); System.exit(1); } //BJCHEREFIRST final List tList = new ArrayList(); // read a list of people from a file final BufferedReader tInputHandle = new BufferedReader(new FileReader(pArgs[0])); while (true) { final String tFileLine = tInputHandle.readLine(); if (tFileLine==null) { break; } final Person tFilePerson = new PersonImpl(tFileLine); tList.add(tFilePerson); } // tList.add(new java.util.Date()); // output the list that has been read in final Iterator tIterator = tList.iterator(); while (tIterator.hasNext()) { final Person tIteratePerson = tIterator.next(); System.out.println(tIteratePerson); } // ask the user to examine the list final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("Person? "); System.out.flush(); final String tKeyboardLine = tKeyboard.readLine(); if (tKeyboardLine.equals("")) { break; } final Person tTargetPerson = new PersonImpl(tKeyboardLine); final int tPosition = tList.indexOf(tTargetPerson); System.out.print(tTargetPerson); if (tPosition>=0) { System.out.println(" is at position " + tPosition); } else { System.out.println(" is absent"); } } } }