// A program that tests the Pop interface and the PopImpl class. // Barry Cornelius, 19 June 2000 import java.io. BufferedReader; import java.io. InputStreamReader; import java.io. IOException; public class PopImplProg { private static Pop iPop; private static BufferedReader iKeyboard; public static void main(final String[] pArgs) throws IOException { iPop = new PopImpl(); iKeyboard = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("Command? "); System.out.flush(); final char tCommand = iKeyboard.readLine().toLowerCase().charAt(0); if (tCommand=='q') { break; } iProcessCommand(tCommand); System.out.println(); } } private static void iProcessCommand(final char pCommand) throws IOException { switch (pCommand) { case 'a': { System.out.print("Person? "); System.out.flush(); final Person tPerson = new PersonImpl(iKeyboard.readLine()); if ( ! iPop.add(tPerson) ) { System.out.println("The person is already in the population"); } } break; //BJCHEREFIRST case 'd': { iPop = new PopImpl(); } break; case 'g': { System.out.print("Name? "); System.out.flush(); final String tName = iKeyboard.readLine(); final Person tPerson = iPop.get(tName); if (tPerson==null) { System.out.println("No such person in the population"); } else { System.out.println(tPerson); } } break; case 'r': { System.out.print("Name? "); System.out.flush(); final String tName = iKeyboard.readLine(); if ( ! iPop.remove(tName) ) { System.out.println("The person is not in the population"); } } break; default: { System.out.println(pCommand + " is not a valid command letter"); } break; } } }