Sjfcodes
Sjfcodes
List;
int [] temp;
int [] tempWaitinTime;
int commBT, k, tq;
int[][] d;
int btcache;
void start( ){
for (int i = 0; i < d.length; i++) {
int bt = d[i][1];
if( bt > 0){
if( bt <= tq){
temp[i] = btcache+bt;
btcache = temp[i];
k += bt;
bt -= bt;
}
else{
temp[i] = btcache+tq;
btcache = temp[i];
bt -= tq;
k += tq;
}
d[i][1] = bt;
}
}
if( k!= commBT)
start();
}
System.out.println("============================================ ");
System.out.println("Process ID | Turnaround time | Waiting time ");
System.out.println("============================================ ");
Object[] job = jobList.toArray();
for (int i : temp) {
Job job1 = (Job) job[c-1];
System.out.println( " " + c + " | " + i +" | "+(i-
job1.getCpuTime()));
System.out.println("----------------------------------------");
avgTurnArroundTime += i;
avgWaitigTime += (i-job1.getCpuTime());
c++;
}
System.out.println("===============================================
");
System.out.println( "Avg waiting time = " + avgWaitigTime/temp.length);
System.out.println("===============================================
");
System.out.println( "Avg turn round time = " +
avgTurnArroundTime/temp.length);
System.out.println("===============================================
");
}
public void run(List<Job> jobList, int quantum) {
int m = job.getCpuTime();
d[count][1] = m;
commBT += m;
count++;
}
tq = quantum;
start();
display(jobList);
}
}
AllocationStrategy.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
Job.java
this.processId = processId;
this.arrivalTime = arrivalTime;
this.cpuTime = cpuTime;
}
JobFinishEvent.java
Question1.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Question1 {
String filename ;
String allocationStrategy;
int quantum=20;
/*filename = args[0];
allocationStrategy = args[1];*/
filename = "testing.txt";
allocationStrategy = "FCFS";
//filename = sc.nextLine();
if(args.length==3){
quantum = new Integer(args[2]);
}
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new
FileReader("C://Users/Arnav/Desktop/"+filename));
//System.out.println("processId arrivalTime cpuTime");
jobList.add(job);
if("FCFS".equalsIgnoreCase(allocationStrategy)){
}else if("SRT".equalsIgnoreCase(allocationStrategy)){
}else if("RR".equalsIgnoreCase(allocationStrategy)){
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}