Question: i have this java code and i need to paraphrase it ( make it look like a new / unique code since i used it

i have this java code and i need to paraphrase it (make it look like a new/unique code since i used it last year ) without changing the context and output results and please make sure it works after the changes (for example change every variable name and function and any changable thing to make it look unique / make each process id in a table for example of something ):
import java.util.*;
class Process {
int id;
int burstTime;
int arrivalTime;
int priority;
int remainingTime;
int waitingTime;
int turnaroundTime;
int responseTime;
boolean isComplete;
boolean isFirstCycle;
public Process(int id, int arrivalTime, int burstTime, int priority){
this.id = id;
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
this.priority = priority;
this.remainingTime = burstTime;
this.waitingTime =0;
this.turnaroundTime =0;
this.responseTime =-1;
this.isComplete = false;
this.isFirstCycle = true;
}
// Getter for priority
public int getPriority(){
return this.priority;
}
// Getter for ID
public int getId(){
return this.id;
}
}
public class PriorityRoundRobinScheduling {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter quantum time:");
int quantum = scanner.nextInt();
List processes = new ArrayList<>();
System.out.println("Enter process ID, arrival time, burst time, and priority (terminate with 0000):");
while (true){
int id = scanner.nextInt();
int arrivalTime = scanner.nextInt();
int burstTime = scanner.nextInt();
int priority = scanner.nextInt();
if (id ==0 && arrivalTime ==0 && burstTime ==0 && priority ==0){
break;
}
processes.add(new Process(id, arrivalTime, burstTime, priority));
}
scanner.close(); // Close the scanner to avoid resource leaks
// Sort processes by arrival time
Collections.sort(processes, Comparator.comparingInt(p -> p.arrivalTime));
int currentTime =0;
int completedProcesses =0;
int totalWaitingTime =0;
int totalTurnaroundTime =0;
int totalResponseTime =0;
StringBuilder ganttChart = new StringBuilder();
while (completedProcesses < processes.size()){
Process current = pickNextProcess(processes, currentTime);
if (current != null){
if (current.isFirstCycle){
current.responseTime = currentTime - current.arrivalTime;
current.isFirstCycle = false;
}
ganttChart.append(" p").append(current.id).append("-");
int timeSlice = Math.min(quantum, current.remainingTime);
currentTime += timeSlice;
current.remainingTime -= timeSlice;
if (current.remainingTime ==0){
current.isComplete = true;
completedProcesses++;
current.turnaroundTime = currentTime - current.arrivalTime;
current.waitingTime = current.turnaroundTime - current.burstTime;
totalWaitingTime += current.waitingTime;
totalTurnaroundTime += current.turnaroundTime;
totalResponseTime += current.responseTime;
}
} else {
currentTime++; // Increment the current time if no process is running
ganttChart.append(".");
}
}
System.out.println("Scheduling complete.");
System.out.println("Gantt Chart (RR with Priority): "+ ganttChart.toString().trim());
for (Process p : processes){
System.out.println("Process ID: "+ p.id +
", Turnaround Time: "+ p.turnaroundTime +
", Waiting Time: "+ p.waitingTime +
", Response Time: "+ p.responseTime);
}
System.out.println("Average Turnaround Time: "+(double) totalTurnaroundTime / processes.size());
System.out.println("Average Waiting Time: "+(double) totalWaitingTime / processes.size());
System.out.println("Average Response Time: "+(double) totalResponseTime / processes.size());
}
private static Process pickNextProcess(List processes, int currentTime){
return processes.stream()
.filter(p ->!p.isComplete && p.arrivalTime <= currentTime)
.min(Comparator.comparingInt(Process::getPriority).thenComparingInt(Process::getId))
.orElse(null);
}
}

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!