Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING JAVA:: An operating system assigns jobs to print queues based on the numbe

ID: 3688759 • Letter: U

Question

USING JAVA::

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

Queue A: less than ten pages.

Queue B: at least ten pages but less than twenty pages.

Queue C: at least twenty pages, but no more than fifty pages.

The computer system uses three printers, one assigned to each queue, each capable of printing ten pages per minute.

Assume that a print request arrives every minute, for each request the number of pages to be printed is a random integer between one and fifty, and a job is assigned to a queue according to the number of pages to be printed. In each queue, the jobs are processes in the order in which they are received. (The printers operate simultaneously. Your program should prompt for number of jobs to be run and should output the order the jobs were received, the order in which they were printed, the printer they were printed on, and the total time required to process the set of jobs.

Explanation / Answer

package assignment;

import java.util.Random;
import java.util.Scanner;

public class PrinterJobQueue {
   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);
       String option = null;
       int noOfPages = 0;
       Random rand = new Random();
       String str = "";
       int i = 1;
       int total = 0;
       do {

           int max = 50;
           int min = 1;

           noOfPages = (rand.nextInt((max - min) + 1) + min);
          
           System.out.println("No of pages to be printed in Job:"+noOfPages);
           //Determine which printer
           if(noOfPages < 10) {
               str += "Job #"+i+" Printer: Queue A Time to process (min): 1";
               total += 1;
           }
           if(noOfPages >= 10 && noOfPages < 20) {
               if(noOfPages == 10) {
                   str += "Job #"+i+" Printer: Queue B Time to process (min): 1";
                   total += 1;
               } else {
                   str += "Job #"+i+" Printer: Queue B Time to process (min): 2";
                   total += 2;
               }
              
           }
          
           if(noOfPages >= 20 && noOfPages < 50) {
               int time = 0;
               if(noOfPages % 5 == 0)
                   time = noOfPages / 5;
               else
                   time = noOfPages / 5 +1;
                   str += "Job #"+i+" Printer: Queue B Time to process (min): "+time;
                   total += time;
              
           }
           str += " ";
           System.out.println("Are you want to continue: (Y/N)?");
           option = scan.next();
           i++;

       } while (!"N".equalsIgnoreCase(option));
       System.out.println("Report: "+str);
       System.out.println("Total time taken(min): "+total);
   }

}


---output-------------

No of pages to be printed in Job:30
Are you want to continue: (Y/N)?
y
No of pages to be printed in Job:13
Are you want to continue: (Y/N)?
y
No of pages to be printed in Job:38
Are you want to continue: (Y/N)?
y
No of pages to be printed in Job:8
Are you want to continue: (Y/N)?
n
Report:
Job #1 Printer: Queue B Time to process (min): 6
Job #2 Printer: Queue B Time to process (min): 2
Job #3 Printer: Queue B Time to process (min): 8
Job #4 Printer: Queue A Time to process (min): 1

Total time taken(min): 17