PLEASE MAKE THS ON EXCEL FLE
LNK
https://www.chegg.com/homework-help/questions-and-answers/term-project-2-details-scope-term-project-aims-combine-knowledge-quin-theory-analysis-deve-q90870037?trackid=ygpBDhnz
Step 1 of 1 // import java.io.File; import java.io.FileNotFoundException; import java.util. *; public class Process SchedulingEngine { static Process[] processArr; static int quantum public static void main(String[] args) throws FileNotFoundException, InterruptedException { Thread initializerThread = new Thread(new Runnable() { @Override public void run() { System.out.println("Running the initializer thread."); try { initializer(processArr, quantum); initializer(); } catch (FileNotFoundException e) { e.printStackTrace(): } } }); initializerThread.start(); initializerThread.join(); Thread schedulerThread = new Thread(new Runnable() { @Override public void run() { System.out.println("Running the scheduler thread."); schedulerThread(processArr, quantum); } }); schedulerThread.start(); } private static void scheduler Thread(Process[] processArr, int quantum) { System.out.println("Running the scheduler thread."); System.out.println("Process Arr : " + processArr.length); // this creates a priority queue(order) of the processes to be run // create custom scheduler as per the given condition Queue
(new CustomScheduler(); 1/ add all the processes to the queue for (int i = 0; i processQueue = new PriorityQueue(new CustomScheduler()); // add all the processes to the queue for (int i = 0; i quantum) current setExecution Time (current.getExecution Time()- quantum); current.setArrival Time(current.getArrivalTime()+quantum); process Queue.add(current); } } } public static void initializer() throws FileNotFoundException { System.out.println("Running the initializer method."); Scanner sc = new Scanner(new File("src/Chegg/java/processinput.txt")); int index = -1; while (schasNextLine()) { String line = sc.nextLine(); System.out.println("Process Line :" + line); if (line.split("").length == 2) { int n_proc = Integer.parseInt(line-split(", ")[0]); quantum = Integer.parseInt(line.split("")[1]); processArr = new Process[n_proc); } else { index++ String[] processinfo = line.split(""); System.out.println("Process info : " + processinfo[0] + ", " + processinfo[1] + ", " + processinfo[2] + ", " + processInfo[3]); processArr[index] = new Process(Integer.parseInt(processInfo[0]), Integer.parseInt(processInfo[1]), Integer.parseInt(processinfo[2]), Integer.parseInt(processinfo[3])); = } class Process int[] processIDArray = new int[1001]; int identifier int arrival Time int executionTime; int priority; public Process() { Random random = new Random(): int next = random.nextInt(1001); while (processIDArray[next] != 0) { next = random.nextInt(1001); } if (processIDArray[next] == 0) this.identifier = next; this arrival Time = 0; this.execution Time = 0; this priority = 0; } public Process(int identifier, int arrivalTime, int execution Time, int priority) { this identifier = identifier; this arrival Time = arrivalTime; this.execution Time = execution Time; this priority = priority; = } public int getldentifier() { return identifier } public void setidentifier(int identifier) { this.identifier = identifier, } public int getArrivalTime() { return arrivalTime; } public void setArrivalTime(int arrivalTime) { this arrival Time = arrival Time; } public int getExecution Time() { return execution Time; } public void setExecution Time(int execution Time) { this.execution Time = execution Time; } public int getPriority() { return priority: @Override public String to String() { return "Process(" + "identifier=" + identifier + ", arrivalTime=" + arrival Time + execution Time=" + execution Time + ", priority=" + priority + '}; } } class CustomScheduler implements Comparator { @Override public int compare(Process 01, Process 02) { // if o1 has lesser arrival time, prioritize it first if (01.getArrivalTime() > 02.getArrivalTime()) { return 1; } else if (01.getArrivalTime() == 02.getArrivalTime()) { Il if arrival time is same, then choose the one with smaller identifier value if (01.getidentifier() > 02.getIdentifier()) { return 1; } } return -1; Sample Output Running the initializer thread Running the initializer method. Process Line : 3,5 Process Line : 1,5,8,1 Process info : 1, 5, 8, 1 Process Line : 2,0,10,2 Process info : 2,0, 10,2 Process Line : 3,10,7,3 Process info: 3, 10, 7,3 Running the scheduler thread. Running the scheduler thread. Process Arr :3 Running the processes Process{identifier=2, arrival Time=0, execution Time=10, priority=2} Process{identifier=1, arrival Time=5, execution Time=8, priority=1} Process{identifier=2, arrival Time=5, execution Time=5, priority=2} Process{identifier=1, arrival Time=10, execution Time=3, priority=1} Process{identifier=3, arrivalTime=10, execution Time=7, priority=3} Process{identifier=3, arrivalTime=15, execution Time=2, priority=3 Explanation Please refer to solution in this step