import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Queue;
/* implement this class for all three strategies */
public abstract class AllocationStrategy { protected List Jobs; protected ArrayList Queue; public AllocationStrategy(List jobs) { super(); Jobs = jobs; } public abstract void run(); // update current job by 1 tick // check if the job queue might need to be changed. // check for jobs to add to the queue
}
FirstComeFirstServed.java
import java.util.ArrayList; import java.util.List;
public class FirstComeFirstServed extends AllocationStrategy {
int temp; int proceessArrivalTime; int waitingTime; double avgWaitingTime; double avgTurnAroundTime; public FirstComeFirstServed(List jobs) { super(jobs); }
@Override public void run() {
}
public void run(List jobList) { int count = 0; System.out.println("============================================ "); System.out.println("Process ID | Turnaround time | Waiting time "); System.out.println("============================================ "); for(Job job:jobList){ if(count==0){ job.processArrivalTime = job.getArrivalTime(); job.ProcessCompletionTime = job.getArrivalTime()+job.getCpuTime(); }else{ job.processArrivalTime = temp-job.getArrivalTime(); job.ProcessCompletionTime = temp+job.getCpuTime(); } temp = job.ProcessCompletionTime; job.turnAroundTime = temp-job.getArrivalTime(); job.waitingTime = job.turnAroundTime-job.getCpuTime(); count++; avgWaitingTime = avgWaitingTime+job.waitingTime; avgTurnAroundTime = avgTurnAroundTime+job.turnAroundTime; System.out.println(" "+job.getProcessId()+" | "+" "+job.turnAroundTime+" | "+" "+job.waitingTime+" "); System.out.println("----------------------------------------"); }