import java.util.*; import java.io.*; public class CarWashTester { protected CarWash carWash; /** * Initializes this CarWashTester object. * */ public CarWashTester () { carWash = new CarWash(); } // default constructor /** * Reads in all of the arrival times, runs the simulation, and calculates the average * waiting time. * */ public void readAndProcessArrivalTimes() { final int SENTINEL = 999; final String PROMPT = "\nPlease enter the next arrival time. The sentinel is " + Integer.toString (SENTINEL) + ": "; final String OUT_OF_RANGE = " The input must consist of a non-" + "negative integer less than the sentinel."; BufferedReader keyboardReader = new BufferedReader (new InputStreamReader (System.in)); String line; int nextArrivalTime; while (true) { System.out.print (PROMPT); try { line = keyboardReader.readLine(); nextArrivalTime = Integer.parseInt (line); if (nextArrivalTime == SENTINEL) break; if (nextArrivalTime < 0 || nextArrivalTime > SENTINEL) System.out.println (OUT_OF_RANGE); else carWash.process (nextArrivalTime); } // try catch (IOException e) { System.out.println(e); } // catch IOException catch (IllegalArgumentException e) { System.out.println (e); } // catch IllegalArgumentException } // while carWash.finishUp(); } // readAndProcessArrivalTimes /** * Prints the results of the simulation. * */ public void printResults() { final String RESULTS_HEADING = "\nHere are the results of the simulation:\n"; LinkedList results = carWash.getResults(); System.out.println (RESULTS_HEADING); for (String s : results) System.out.print (s); } // method printResults } // class CarWashTester