// A program that performs operations on a queue of people. // Barry Cornelius, 19 June 2000 import java.io. BufferedReader; import java.io. InputStreamReader; import java.io. IOException; public class PersonLinkedQueueProg { private static Queue iPersonQueue; private static BufferedReader iKeyboard; public static void main(final String[] pArgs) throws IOException { iPersonQueue = new LinkedQueue(); 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()); iPersonQueue.add(tPerson); } break; case 'd': { iPersonQueue = new LinkedQueue(); } break; //BJCHEREFIRST case 'e': { System.out.print("The queue is "); if (iPersonQueue.size()!=0 ) { System.out.print("not "); } System.out.println("empty"); } break; case 'g': { if (iPersonQueue.size()==0) { System.out.println("The queue is empty"); } else { final Person tPerson = (Person)iPersonQueue.getFirst(); System.out.println("The first person is: " + tPerson); } } break; case 'r': { if (iPersonQueue.size()==0) { System.out.println("The queue is empty"); } else { final Person tPerson = (Person)iPersonQueue.remove(); System.out.println(tPerson + " has been removed"); } } break; default: { System.out.println(pCommand + " is not a valid command letter"); } break; } } }