This question would have been a prime candidate to familarise yourself with using a debugger.
@Marce Puente has already pointed out the difference between the expected and actual values of ganttChart
in his answer. As it turns out, the scheduler will never switch back to a task it ever switched away from. That is because getShortestRemainingTimeProcess(...)
will, correctly, remove the selected proccess from the ready queue, since its about to be executing. However, nothing ever adds back proccesses that were context switched away from, leading to proccesses potentially never finishing their jobs.
The formula for cpuUtil
doesn't substract time spent on context switches. Thats time the CPU is somewhat occupied, but usally not moddeled because it might just be the memory controller moving stuff between main memory and the CPU cache.
The format strings of the last three System.out.printf()
calls in printResults()
don't match the format in the expected output. Thus:
System.out.printf("Average Turnaround Time: %.0f\n", avgTurnaround);
System.out.printf("Average Waiting Time: %.1f\n", avgWaiting);
System.out.printf("CPU Utilization: %.2f\n", cpuUtil);