We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0ee93cc commit 920ce38Copy full SHA for 920ce38
src/main/java/com/thealgorithms/scheduling/LotteryScheduling.java
@@ -53,6 +53,13 @@ public List<Process> scheduleProcesses() {
53
int winningTicket = random.nextInt(totalTickets) + 1;
54
Process selectedProcess = selectProcessByTicket(winningTicket);
55
56
+ if (selectedProcess == null) {
57
+ // This should not happen in normal circumstances, but we'll handle it just in case
58
+ System.err.println("Error: No process selected. Recalculating total tickets.");
59
+ totalTickets = processes.stream().mapToInt(Process::getTickets).sum();
60
+ continue;
61
+ }
62
+
63
selectedProcess.setWaitingTime(currentTime);
64
currentTime += selectedProcess.getBurstTime();
65
selectedProcess.setTurnAroundTime(selectedProcess.getWaitingTime() + selectedProcess.getBurstTime());
0 commit comments