79485927

Date: 2025-03-05 09:07:16
Score: 0.5
Natty:
Report link

Preamble

This question would have been a prime candidate to familarise yourself with using a debugger.

Bugged Scheduling

@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.

Bugged statistics

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.

Output formatting

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);
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Marce
  • Low reputation (1):
Posted by: Jannik S.