Monday 7 August 2017

fcfs.java (OS)

import java.util.Scanner;

class fcfs
{
public static void main(String ... args)
{
int n,curTime=0,sumTAT=0,sumWT=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of process : ");
n = sc.nextInt();
int AT[]=new int[n];
int BT[]=new int[n];
int WT[]=new int[n];
int TAT[]=new int[n];
for(int i=0; i<n; i++)
{
System.out.println("Enter AT of #"+(i+1)+"No.: ");
AT[i]=sc.nextInt();
System.out.println("Enter BT of #"+(i+1)+"No.: ");
BT[i]=sc.nextInt();
}
for(int i=0; i<n; i++)
{
WT[i]=curTime-AT[i];
curTime+=BT[i];
TAT[i]=curTime-AT[i];
sumWT+=WT[i];
sumTAT+=TAT[i];
}
System.out.println("AT\tBT\tWT\tTAT\n-------------------------------");
for(int i=0; i<n; i++)
System.out.println(AT[i]+"\t"+BT[i]+"\t"+WT[i]+"\t"+TAT[i]);
System.out.println("AvgWT = " + ((float)  sumWT/n) +"\nAvgTAT = " +  ((float) sumTAT/n));
}
}

Output:

E:\os write ups>javac fcfs.java

E:\os write ups>java fcfs

Enter number of process :
5
Enter AT of #1No.:
5
Enter BT of #1No.:
6
Enter AT of #2No.:
2
Enter BT of #2No.:
1
Enter AT of #3No.:
7
Enter BT of #3No.:
8
Enter AT of #4No.:
5
Enter BT of #4No.:
4
Enter AT of #5No.:
6
Enter BT of #5No.:
2
AT      BT      WT      TAT
-------------------------------
5       6       -5      1
2       1       4       5
7       8       0       8
5       4       10      14
6       2       13      15
AvgWT = 4.4
AvgTAT = 8.6

No comments:

Post a Comment