Need a program that will simulate FCFS algorithms. The program should compute turnaround time for every job,
Question:
Need a program that will simulate FCFS algorithms. The program should compute turnaround time for every job, as well as the average turnaround time.
Code given:
public class Process{
String pJob;
int pArrivalTime;
int pCPUCycle;
Process(String Job, int ArrivalTime, int CPUCycle){
pJob = Job;
pArrivalTime = ArrivalTime;
pCPUCycle = CPUCycle;
}
public String getJob(){
return pJob;
}
public int getArrivalTime(){
return pArrivalTime;
}
public int getCPUCycle(){
return pCPUCycle;
}
public String toString(){
return "Job: " + pJob + " " + "Arrival Times: " + pArrivalTime + " " + "CPU Cycle (in ms): " + pCPUCycle;
}
}
import java.util.*;
public class ProcessList {
public ArrayList pList;
ProcessList( ) {
pList = new ArrayList ();
pList = new ArrayList ();
pList.add(new Process("A", 0, 16));
pList.add(new Process("B", 3, 2));
pList.add(new Process("C", 5, 11));
pList.add(new Process("D", 9, 6));
pList.add(new Process("E", 10, 1));
pList.add(new Process("F", 12, 9));
pList.add(new Process("G", 14, 4));
pList.add(new Process("H", 16, 14));
pList.add(new Process("I", 17, 1));
pList.add(new Process("J", 19, 8));
}
public void printProcessList(){
}
public double calTurnaround( ){
}
public static void main(String[] args) {
double aveTurnaround;
ProcessList pl = new ProcessList();
pl.printProcessList();
aveTurnaround = pl.calTurnaound();
}
}
Turnaround times for each job is computed by job finish time - job arrival time. I have computed them for you:
Turnaround times:
Job | Finish time | Arrival time | turnaround time |
A | 16 | 0 | 16 |
B | 18 | 3 | 15 |
C | 29 | 5 | 24 |
D | 35 | 9 | 26 |
E | 36 | 10 | 26 |
F | 45 | 12 | 33 |
G | 49 | 14 | 35 |
H | 63 | 16 | 47 |
I | 64 | 17 | 47 |
j | 72 | 19 | 53 |
Finish time can be found by adding the finish time of the last job to the CPU cycle. For example, Job A finishes at 16, so Job B will have a finish time at 18 because the CPUcycle is 2, and 16+2 is 18
Expected Output:
Basic Technical Mathematics
ISBN: 9780137529896
12th Edition
Authors: Allyn J. Washington, Richard Evans