Question: I am trying to implement the shortest job first scheduling algorithm in java, however i need help filling in the else statement. import java.util.ArrayList; public

I am trying to implement the shortest job first scheduling algorithm in java, however i need help filling in the else statement.

import java.util.ArrayList;

public class SJF { private Process shortest; private int quantum; private ArrayList process; private ArrayList queue; private ArrayList stat; private ArrayList output; public SJF(ArrayList process) // received data { this.shortest = new Process(); // created a new process this.quantum = quantum; this.process = process; this.queue = new ArrayList(); this.stat = new ArrayList(); this.output = new ArrayList(); run(); }

private void run() { while (quantum < 100) //requirements { while (quantum < 100) { // add all process for (Process p: process) { if (p.getArrivalTime() < quantum) // if arrival time < 100 { queue.add(p); } } process.removeAll(queue); // remove process that has been added to the queue //if queue is empty, add null. //else add shortest process if(queue.isEmpty()) { output.add(""); //queue is null quantum++; } else { // i need help here } } } }

}

this is the Process class.

import java.util.Random;

public class Process { private float arrivalTime; //[0 - 99] private float runTime; //[.1 - 10] private int priority; //[1 - 4] private String name; private int actualStartTime; private int quantumWaitAmount; private int endTime; private float quantaTime;

/** * Creates a new process */ public Process() { int seed = 1; //Can be used with Random(seed) to guarantee the same values each run Random r = new Random(); arrivalTime = r.nextFloat() * 99; runTime = r.nextFloat() * 10; if(runTime == 0) runTime += .1; priority = r.nextInt(4) + 1; quantumWaitAmount = 0; actualStartTime = -1; endTime = -1; quantaTime = 0.0f; }

public float getArrivalTime() { return arrivalTime; }

public float getRunTime() { return runTime; }

public int getPriority() { return priority; }

public String getName() { return name; }

public void setArrivalTime(float arrivalTime) { this.arrivalTime = arrivalTime; }

public void setRunTime(float runTime) { this.runTime = runTime; }

public void setPriority(int priority) { this.priority = priority; }

public void setName(String name) { this.name = name; } public void setActualStartTime(int actualStartTime) { if(this.actualStartTime < 0) { this.actualStartTime = actualStartTime; } } public void decrementQuantumWaitTimeAmount() { quantumWaitAmount--; } public void incrementQuantumWaitAmount() { quantumWaitAmount++;

if(quantumWaitAmount == 5) { quantumWaitAmount = 0;

increasePriority(); } } public void decrementRunTime() { runTime--; } public float getQuantaTime() { return quantaTime; } public void incrementQuantaTime() { this.quantaTime = quantaTime++; } public void setEndTime(int endTime) { this.endTime = endTime; } public void increasePriority() { if(priority > 1) { priority--; } }

public String printProcess() { return String.format("Process Name: %s, Arrival Time: %s, Runtime: %s, Priority: %s", name, arrivalTime, runTime, priority); } }

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!