CMSC 206: Data Structures
Assignment#5

Due on Tuesday, Nov. 10, 2015

 

Simulating a Printer Usage

A Computer Lab has a monochrome printer that prints 10 pages per minute. In any given hour there are 10 students working on their assignments. Each student prints something on the printer up to twice in an hour. Each print job could be anywhere from 1 to 20 pages long. That is, there are, on average, 20 print jobs in an hour. Do a simulation (as described in class) to determine, in an hour, what the average wait time for a student to wait for their print jobs to be finished. Based on the results, answer the following:

1. Is the wait time reasonable? (What is reasonable? You decide)
2. What would be the average wait time, if the printer were replaced by a new color printer. However, it prints at 5 pages per minute.

Technical Hints:

As designed in class, you will need the following two classes: Task, and Printer. Use the code provided. The skeletal main program is also provided here. Also, the main simulation algorithm is described below:

   
simulate(seconds, ppm) : Perform the simulation for given time (seconds) for a printer that prints at speed (ppm)

   - Create a new printer at speed ppm
   - Create a new printerQueue (a queue of Tasks)
   - Create an array to record wait times

   - for each tick (second)
       - if there is a new task (see function newTask())
           - create a new task and add it to the printerQueue

       - if printer is not busy the printerQueue is not empty
           - record wait time for this task
           - remove next task from printerQueue
           - start the next task on the printer

       - printer prints for 1 second

   - compute average wait time & print results

What to Hand-in (on Moodle):

A zip file containing:
  1. .java and .class file(s) for your program (in the correct directories if they are in packages.
  2. a text file of your program results showing the results for simulations requested.
  3. Answer to the two questions posed above.

Back to CS206 Course Materials