Question: This is a Java project involving a CPU scheduling simulation. Completing it will require writing the following Java classes: FCFS.java SJF.java RR.java Priority.java PriorityRR.java Each

This is a Java project involving a CPU scheduling simulation. Completing it will require writing the following Java classes:

FCFS.java SJF.java RR.java Priority.java PriorityRR.java

Each of these classes must implement the Algorithm.java interface and utilize the remaining code.

//=======rrschedule.txt===========================

T1, 40, 50 T2, 40, 50 T3, 40, 50 T4, 40, 50 T5, 40, 50 T6, 40, 50

//================run.txt========================= Priority with RR Scheduling

Will run Name: T8 Tid: 7 Priority: 10 Burst: 25

Task T8 finished.

Will run Name: T4 Tid: 3 Priority: 5 Burst: 15

Will run Name: T5 Tid: 4 Priority: 5 Burst: 20

Will run Name: T4 Tid: 3 Priority: 5 Burst: 5

Task T4 finished.

Will run Name: T5 Tid: 4 Priority: 5 Burst: 10

Task T5 finished.

Will run Name: T1 Tid: 0 Priority: 4 Burst: 20

Task T1 finished.

Will run Name: T2 Tid: 1 Priority: 3 Burst: 25

Will run Name: T3 Tid: 2 Priority: 3 Burst: 25

Will run Name: T7 Tid: 6 Priority: 3 Burst: 30

Will run Name: T2 Tid: 1 Priority: 3 Burst: 15

Will run Name: T3 Tid: 2 Priority: 3 Burst: 15

Will run Name: T7 Tid: 6 Priority: 3 Burst: 20

Will run Name: T2 Tid: 1 Priority: 3 Burst: 5

Task T2 finished.

Will run Name: T3 Tid: 2 Priority: 3 Burst: 5

Task T3 finished.

Will run Name: T7 Tid: 6 Priority: 3 Burst: 10

Task T7 finished.

Will run Name: T6 Tid: 5 Priority: 1 Burst: 10

Task T6 finished.

//==============schedule.txt================ T1, 4, 20 T2, 3, 25 T3, 3, 25 T4, 5, 15 T5, 5, 20 T6, 1, 10 T7, 3, 30 T8, 10, 25

//=============Driver.java========================== package cpuscheduling; import java.util.*; import java.io.*;

public class Driver{ public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("Usage: java Driver "); System.exit(0); } BufferedReader inFile = new BufferedReader(new FileReader(args[1])); String schedule; List queue = new ArrayList();// create the queue of tasks

// read in the tasks and populate the ready queue while ( (schedule = inFile.readLine()) != null) { String[] params = schedule.split(",\\s*"); queue.add(new Task(params[0], Integer.parseInt(params[1]), Integer.parseInt(params[2]))); } inFile.close(); Algorithm scheduler = null; String choice = args[0].toUpperCase(); switch(choice) { case "FCFS": scheduler = new FCFS(queue); break; case "SJF": scheduler = new SJF(queue); break; case "PRI": scheduler = new Priority(queue); break; case "RR": scheduler = new RR(queue); break; case "PRI-RR": scheduler = new PriorityRR(queue); break; default: System.err.println("Invalid algorithm"); System.exit(0); }

// start the scheduler scheduler.schedule(); } }

//===================CPU.java======================= package cpuscheduling; public class CPU { /** * Run the specified task for the specified slice of time. */ public static void run(Task task, int slice) { System.out.println("Will run " + task); } }

//==================Algorithm.java================= package cpuscheduling;

public interface Algorithm{ public abstract void schedule(); public abstract Task pickNextTask(); }

//====================Task.java==================== package cpuscheduling; import java.util.concurrent.atomic.AtomicInteger;

public class Task{ // the representation of each task private String name; private int tid; private int priority; private int burst; /** We use an atomic integer to assign each task a unique task id.*/ private static AtomicInteger tidAllocator = new AtomicInteger();

public Task(String name, int priority, int burst) { this.name = name; this.priority = priority; this.burst = burst;

this.tid = tidAllocator.getAndIncrement(); }

/** Appropriate getters*/ public String getName() { return name; }

public int getTid() { return tid; }

public int getPriority() { return priority; }

public int getBurst() { return burst; }

/** * Appropriate setters */ public int setPriority(int priority) { this.priority = priority;

return priority; } public int setBurst(int burst) { this.burst = burst;

return burst; }

/** We override equals() so we can use a Task object in Java collection classes.*/ public boolean equals(Object other) { if (other == this) return true;

if (!(other instanceof Task)) return false;

/** * Otherwise we are dealing with another Task. * two tasks are equal if they have the same tid. */ Task rhs = (Task)other; return (this.tid == rhs.tid) ? true : false; }

public String toString() { return "Name: " + name + " " + "Tid: " + tid + " " + "Priority: " + priority + " " + "Burst: " + burst + " "; } }

Each of the classes (FCFS.java, SJF.java, RR.java, Priority.java and PriorityRR.java) must be created and must implement the code above.

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!