Question: please help me translate this peasdocode into working java code, its answering the question in the attached photo class Process: def _ _ init _

please help me translate this peasdocode into working java code, its answering the question in the attached photo
class Process:
def __init__(self, id, service_time, arrival_time):
self.id = id
self.service_time = service_time
self.remaining_time = service_time
self.arrival_time = arrival_time
self.start_time = None
self.end_time = None
self.initial_wait_time = None
self.total_wait_time =0
def round_robin_scheduling(processes, quantum, context_switch):
time =0
process_queue =[]
completed_processes =[]
while True:
# Load arriving processes into the queue
for process in processes:
if process.arrival_time == time:
process_queue.append(process)
if not process_queue and all(p.remaining_time ==0 for p in processes):
break # All processes are completed
if process_queue:
current_process = process_queue.pop(0)
if current_process.start_time is None:
current_process.start_time = time
if current_process.initial_wait_time is None:
current_process.initial_wait_time = time - current_process.arrival_time
execution_time = min(current_process.remaining_time, quantum)
current_process.remaining_time -= execution_time
time += execution_time
if current_process.remaining_time >0:
process_queue.append(current_process)
else:
current_process.end_time = time
completed_processes.append(current_process)
# Add context switch time if there are more processes in the queue
if process_queue:
time += context_switch
for process in process_queue:
process.total_wait_time += execution_time +(context_switch if process_queue.index(process)!=0 else 0)
else:
time +=1 # Increment time if no process is in the queue
# Calculate total wait time and turnaround time
for process in completed_processes:
process.total_wait_time += process.initial_wait_time
process.turnaround_time = process.end_time - process.arrival_time
# Output results
print("Process ID | Start Time | Initial Wait Time | End Time | Total Wait Time | Turnaround Time")
for process in completed_processes:
print(f"{process.id}|{process.start_time}|{process.initial_wait_time}|{process.end_time}|{process.total_wait_time}|{process.turnaround_time}")
# Define processes based on the given table
processes =[
Process(1,75,0),
Process(2,40,10),
Process(3,25,10),
Process(4,20,80),
Process(5,45,85)
]
# Case 1: Quantum =10, Context Switch =0
print("Case 1: Quantum =10, Context Switch =0")
round_robin_scheduling(processes,10,0)
# Reset processes for Case 2
processes =[
Process(1,75,0),
Process(2,40,10),
Process(3,25,10),
Process(4,20,80),
Process(5,45,85)
]
# Case 2: Quantum =10, Context Switch =2
print("
Case 2: Quantum =10, Context Switch =2")
round_robin_scheduling(processes,10,2)Case 1: Quantum =10, context switch =0
Case 2: Quantum =10, context switch =2
 please help me translate this peasdocode into working java code, its

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!