Round Robin

Published on February 2017 | Categories: Documents | Downloads: 60 | Comments: 0 | Views: 324
of 3
Download PDF   Embed   Report

Comments

Content

package FCFS; import java.util.HashMap; import java.util.Random; public class RoundRobin { int no_of_process; public HashMap burstTime = new HashMap(); public int waitingTime[]; public HashMap priority = new HashMap(); public int data[][]; int OTS; int ATS = 6; public RoundRobin(int process, int ots) { no_of_process = process; data = new int[no_of_process][7]; OTS = ots; waitingTime = new int[no_of_process]; } public void setInput() { long mySeed = 100; Random r = new Random(mySeed); // set burst time for (int j = 1; j <= no_of_process; j++) { int burst_Time = (r.nextInt(32)); if(burst_Time ==0 ) burst_Time = 12; burstTime.put(j, burst_Time); data[j - 1][0] = j; data[j - 1][1] = burst_Time; data[j - 1][2] = OTS; System.out.print(" " + burst_Time); } // Set priority for (int j = 1; j <= no_of_process; j++) { int burst_Time = (r.nextInt(3)); priority.put(j, burst_Time+1); if (burst_Time == 0) { data[j - 1][3] = 1; } else { data[j - 1][3] = 0; } System.out.print(" \n" + (burst_Time + 1)); }

System.out.println("CC"); // calcoulate SC for (int j = 0; j < no_of_process; j++) { if (data[j][1] - data[j][2] <= OTS) { data[j][4] = 1; } else { data[j][4] = 0; } // csc int cc = data[j][2] + data[j][3] + data[j][4]; System.out.println(cc); if (ATS - cc <= OTS) { data[j][5] = cc-OTS; } else { data[j][5] = 0; } //ITS data[j][6] = data[j][2] + data[j][3] + data[j][4] + data[j][5]; } } public void waitingTime(){ int value =0; for (int j = 0; j < no_of_process; j++) { if(data[j][1]>0){ value = data[j][6]; } int temp = data[j][1]; data[j][1] = data[j][1] - data[j][6]; if(data[j][1]<=0){ data[j][1]=0; } for(int i = 0; i < no_of_process; i++){ if(i != j){ if(data[j][1]>0) waitingTime[i] = waitingTime[i] + value; else waitingTime[i] = waitingTime[i] +temp ; } }

} } public void output() { System.out.println("*********************************"); for (int j = 0; j < no_of_process; j++) { System.out.println(data[j][0] + " " + data[j][1] + " " + data[j][2] + " " + data[j][3] + " " + data[j][4] + " " + data[j][5] + " " + data[j][6]); }

} public static void main(String args[]) { RoundRobin obj = new RoundRobin(5, 4); obj.setInput(); obj.output(); } }

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close