![]() |
![]() |
![]() |
Printer Queue Simulation GUI based Edmonds Community College CS 142 Completed 6/5/2013
Project jar file located: Here
Project .java files located: Here
Problem
Write a program that solves a classic computer science problem known as
client/server problem for print jobs and printers at Alderwood Hall.
Assume there are four servers:
- Printer A
- Printer B
- Printer C
- Printer D
When jobs arrive faster than the printers can begin printing them, they accumulate in the print queue. When all printers are busy, print jobs accumulate in the print queue. When a a printer completes a job it will begin processessing a new print job.
Solution
- PrintQueueSimulationGUI-- the simulation driver class. A GUI based JFrame that allows the user to set/select number of servers (printers), set/select mean interarrival time, and set/select mean duration of each job.
- Client-- Each print job has an instance of this class. It contains a random number generator randomJobSize that generates the exponentially distributed job sizes with a mean of 100 pages. It is declared static because only one instance is needed to produce all the job sizes. Similarly, the static int nextId is used to generate identification numbers for all the jobs. The constructor uses the next Id counter to set the job id, and it uses the randomJobSize generator to set the jobSize. Then it prints one line of output, announcing that that job has arrived. The beginService () method assigns the server reference to the printer that invoked it and then prints one line of output, announcing that the printing has begun. Similarly, the endService() method nullifies the server reference after printing one line of output that announces that the printing has ended.
- Server-- It has a random number generator randomMeanServiceRate that generates the normally distributed rates with mean 100.0 and standard deviation 20.0. It produces the meanServiceRate for each printer. In the run just shown, it produced the rates 89 for Printer A, 97 for Printer B, 106 for Printer C, and 128 for Printer D. Similarly, the random number generator randomServiceRate generates the normally distributed rates for each print job. In the run just shown, it produced the rates 84 for Job #1, 87 for Job #3, and 92 for Job #5. Those came from a normal distribution with mean 89 (for Printer A). The standard deviation is set at 10 for each printer's distribution. The beginServing () method assigns the client reference to the client job that it is printing and obtains the normally distributed serviceRate from the randomServiceRate generator. Then it sends the beginService message to its client print job. Next, the assignment int serviceTime = (int)Math.ceil(client.getJobSize()/serviceRate); computes the time (number of seconds) that it will take to do the print job by dividing the job size (the number of pages) by the printing rate (pages per second). The integer ceiling of this ratio is used as a count of the number of seconds to elapse. This count is then added to the current time to initialize the timeServiceEnds field of the Server object.
- Random-- extends java.utilRandom. Given above.
- Queue--an interface that extends Collection. Public method include enqueue, dequeue, getBack, and getFront. You may decide to implement the Queue class differently--it need not be an interface.
- Client Queue--extends List.
- Splash screen with which the program begins and an About form which describes the project among other info (copyright, warning, logo, etc.).
- A sound data structure of the Person class to hold the preference data. This could be an array, ArrayList, LinkedList (preferable), HashMap, or any other structure you desire.
- Javadocs, description of the program, and comments, comments everywhere.
- Menus that synchronize with corresponding buttons and with at least the
following menu choices:
- File with Open, Clear, Print, Save, and Exit menu items.
- Statistics displaying all averages
- Help with About menu item for an About form.
- The project should start with a Splash Screen that closes itself after so many seconds and it should contain an About form activated from the Help menu.


