-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.java
More file actions
65 lines (60 loc) · 2.48 KB
/
Copy pathFCFS.java
File metadata and controls
65 lines (60 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
public class FCFS {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("enter no of process: ");
int n = sc.nextInt();
int pid[] = new int[n]; // process ids
int ar[] = new int[n]; // arrival times
int bt[] = new int[n]; // burst or execution times
int ct[] = new int[n]; // completion times
int ta[] = new int[n]; // turn around times
int wt[] = new int[n]; // waiting times
int temp;
float avgwt = 0, avgta = 0;
for (int i = 0; i < n; i++) {
System.out.println("process " + (i + 1) + " waktu datang: ");
ar[i] = sc.nextInt();
System.out.println("process " + (i + 1) + " waktu butuh : ");
bt[i] = sc.nextInt();
pid[i] = i + 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - (i + 1); j++) {
if (ar[j] > ar[j + 1]) {
temp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = temp;
temp = bt[j];
bt[j] = bt[j + 1];
bt[j + 1] = temp;
temp = pid[j];
pid[j] = pid[j + 1];
pid[j + 1] = temp;
}
}
}
for (int i = 0; i < n; i++) {
if (i == 0) {
ct[i] = ar[i] + bt[i];
} else {
if (ar[i] > ct[i - 1]) {
ct[i] = ar[i] + bt[i];
} else
ct[i] = ct[i - 1] + bt[i];
}
ta[i] = ct[i] - ar[i]; // turnaround time= completion time- arrival time
wt[i] = ta[i] - bt[i]; // waiting time= turnaround time- burst time
avgwt += wt[i]; // total waiting time
avgta += ta[i]; // total turnaround time
}
System.out.println("\nprocess waktu datang waktu butuh complete turn waiting");
for (int i = 0; i < n; i++) {
System.out
.println(pid[i] + "\t " + ar[i] + "\t " + bt[i] + "\t\t" + ct[i] + "\t" + ta[i] + "\t" + wt[i]);
}
sc.close();
System.out.println("\nrata-rata waiting time: " + (avgwt / n)); // printing average waiting time.
System.out.println("rata-rata turnaround time:" + (avgta / n)); // printing average turnaround time.
}
}