Basic Data Structures and Algorithms Homework Exercises

2324 Words5 Pages

/* CS 113 - Basic Data Structures and Algorithms

* Homework Exercises (70 points)

* *

* Homework #6

*

*

* 1. Programming Projects 5, Page 241

*

* Problem Statement:

* An operating system assigns jobs to print queues based on the number of pages to be printed

* (less than 10 pages, less than 20 pages, or more than 20 pages). You may assume that the

* system printers are able to print 10 pages per minute. Smaller print jobs are printed before

* larger print jobs, and print jobs of the same priority are queued up in the order in which

* they are received. The system administrator would like to compare the time required to process

* a set of print jobs using one, two, or three system printers.

*

* Write a program to simulate processing 100 print jobs of varying lengths using one, two, or

* three printers. Assume that a print request is made every minute and that the number of pages

* to print varies from 1 to 50 pages.

*

* The output from your program should indicate the order in which the jobs were received, the

* order in which they were printed, and the time required to process the set of print jobs.

* If more than one printer is being used, indicate which printer each job was printed on.

*

* Step by Step:

* 1. Import packages from the library.

* 2. Class named PrintTest.

* 2A. Instantiate our constants.

* 2B. Queue handles less than 10 pages.

* 2C. Queue handles less than 20 pages.

* 2D. Queue handles between 21 to 50 pages.

* 2E. The number of print jobs.

* 2F. The maximum number of pages per print job.

* 2G. The printer speed (PPM).

* 2H. Print job queue.

* 2I. Print job queue.

* 2J. Queue of 10.

* 2K. Que...

... middle of paper ...

...ystem.out.println("Size: " + printJob.getNumOfPages());

q10.offer(printJob);

}

else if(printJob.getNumOfPages() < QUEUE20)

{

System.out.println("Queue: " + QUEUE20);

System.out.println("Adding: " + printJob.getName());

System.out.println("Size: " + printJob.getNumOfPages());

q20.offer(printJob);

}

else if(printJob.getNumOfPages() <= QUEUE50)

{

System.out.println("Queue: " + QUEUE50);

System.out.println("Adding: " + printJob.getName());

System.out.println("Size: " + printJob.getNumOfPages());

q50.offer(printJob);

}

else

{

throw new QueueException("Can't process this print job.");

}

}

// 2W. Creates a random number of pages from 1 to 50.

public static int RandomNumberPages()

{

Random r = new Random();

int numOfPages = r.nextInt(MAXPAGES - 1) + 1;

return numOfPages;

}

}

More about Basic Data Structures and Algorithms Homework Exercises

Open Document