Question: 2. This problem is to simulate scheduling CPU jobs by using a priority queue to be built. Your program to be written for the simulation
2. This problem is to simulate scheduling CPU jobs by using a priority queue to be built. Your program to be written for the simulation should run in a loop, each iteration of which corresponds to a time slice for the CPU. Each job is assigned a priority, which is an integer between -10 (highest priority) and +10 (lowest priority), inclusive. Each job is also assigned an arrival time the time at which the job shows up at the CPU. From among all jobs waiting to be processed in a time slice, the CPU, the CPU must work on a job with highest priority. In this simulation, each job will come with arrival time, which is the time at which the job has arrived (integer >= 0). Each job will also include a length value, which is an integer between 1 and 100, inclusive, indicating the number of time slices that are needed to process this job. For simplicity, you may assume jobs cannot be interrupted once it is scheduled on the CPU, a job runs for a number of time slices equal to its length (no preemption). Your simulator must output the name of the job running on the CPU in each time slice as shown below.
Input File format: Each line in the input file contains the details one single job delimited by space. Read the entire file first and then process the priority queue algorithm on all the jobs based on the arrival time. As some jobs will have a different arrival time, the priority queue will have to be re-done after every job is completed and new job arrivals need to be taken into consideration. The order of the jobs in the input file are random and not sorted in any way.
JobName arrivalTime priority lengthOfJob
Example input file:
Job114 0 -9 25
Job345 0 2 66
Job234 10 -10 5
Job999 27 10 56
Output File format: Output on the command line should display the job arrivals on that time slice (if any) and job that is being executed for that timeslice along with the priority and the remaining time of that job.
Time Slice #n Job arrivals at this time slice (if any)
Executing JobName priority remainingLengthOfJob
Example output File: For the same input example file as above, the output should will be as follows:
Time Slice #1 - Job114 arrived
Job345 arrived
Executing Job114 -9 25
Time Slice #2 - Executing Job114 -9 24
Time Slice #3 - Executing Job114 -9 23
Time Slice #4 - Executing Job114 -9 22
Time Slice #5 - Executing Job114 -9 21
.
.
Time Slice #10 - Job234 arrived
Executing Job114 -9 16
Time Slice #11 - Executing Job114 -9 15
Time Slice #12 - Executing Job114 -9 14
Time Slice #13 - Executing Job114 -9 13
Time Slice #14 - Executing Job114 -9 12
Time Slice #15 - Executing Job114 -9 11
Time Slice #16 - Executing Job114 -9 10
.
.
Time Slice #25 - Executing Job114 -9 1
Time Slice #26 - Executing Job234 -10 5
Time Slice #27 - Job999 arrived
Executing Job234 -10 4
Time Slice #28 - Executing Job234 -10 3
Time Slice #29 - Executing Job234 -10 2
Time Slice #30 - Executing Job234 -10 1
Time Slice #31 - Executing Job345 2 66
Time Slice #32 - Executing Job345 2 65
Time Slice #33 - Executing Job345 2 64
Time Slice #34 - Executing Job345 2 63
Time Slice #35 - Executing Job345 2 62
.
.
Time Slice #96 - Executing Job345 2 1
Time Slice #97 - Executing Job999 10 56
Time Slice #98 - Executing Job999 10 55
Time Slice #99 - Executing Job999 10 54
.
.
The output of all the time slices MUST be printed to the console.
A command line user interface to read the input must be provided as follows:
Enter your input file name:
write the code base on java with inpufile.txt. Please do not abuse from different problem sources.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
