PriorityQueue class, which is to have methods to support a simulation as described below. You needn't implement all the binary heap methods of the text. You may ignore the possibility of overflow by making the heap large enough to handle all of the test cases.
Elements of the priority queue are to be of a class Task. Note that this class will have to implement the Comparable interface.
The simulation is to be of a one-processor system where tasks are simply added to the queue randomly, with random priorities and random time requirements. Discrete time steps are to be used in the simulation, beginning with time 0. If the processor is not in use at the beginning of a given time step, the task in the priority queue, if any, with the highest (meaning highest-numbered) priority is deleted from the queue and its execution is simulated for whatever time it requires. Tasks may not be interrupted once they begin executing, even if a higher-priority task enters the queue.
The PriorityQueue class is to have methods to run a simulation for a given number of time steps, to initialize the values used during the simulation, and to print the final values of these statistics. It should have a destructiveTraverse method as described below. All of these except for the initialization should have a parameter of class PrintWriter, so that the methods print and println may be used for output (cf. Appendix A.2 of the text -- these methods may take other types than String). The PriorityQueue class should also have a constructor with arguments representing the number of possible priorities, the maximum possible time requirement of a task, and the probability of a task being added to the queue at a given time step.
The simulation should choose priorities for each task uniformly from 0 up to but not including the maximum possible priority, and time requirements uniformly from 1 through the maximum possible time requirement. Please use a Random object seeded with the value 1 to generate these values, and to determine whether a task is to be added to the queue in the current time step.
Use test file A4.java (available on the class web site) to test your implementation. The summary statistics that should be printed for each simulation are
destructiveTraverse, rather than printStatistics, should do this.
You should record to a log file any instance of a task's being added to the priority queue, with the time it is added. You should also record to this file every instance of a task's being completed. In this case you should give the starting and finishing time of the task. All tasks in a given simulation should have distinct names, and these names should be given in the log in both situations above. The log file corresponds to the PrintWriter parameter for the simulate method. You need not make a hard copy of the log files, but they should appear on your disk. Any information written to System.out should appear on your hard copy.
Note that for each of the two given simulations, tasks are added to the queue once every 10 time steps, on the average. Also note that in the first simulation, the average task requires 10 time steps for its completion, while 10.5 steps are required on the average in the second simulation.
Late submissions for this assignment must be turned in by 4 p.m., Wednesday, November 21. As always, there will be a penalty for late submissions.