This repository has been archived by the owner on Jul 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab9_FCFS.java
92 lines (71 loc) · 3.08 KB
/
Lab9_FCFS.java
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.util.Scanner;
class FCFS{
/*----------------------------------------
| Process_no |Arrival Time|Service Time|
| 1 | 0 | 4 |
...*/
private int[][] table;
private int size;
FCFS(int n){
size=n;
table=new int[n][3];
}
public void enter_table(){
Scanner input=new Scanner(System.in);
System.out.println("Enter the processes in the ascending order of their arriving time");
for(int i=0;i<size;i++)
{
System.out.println("for process"+(i+1));
table[i][0]=(i+1);
System.out.println("enter the process arrival time:");
table[i][1]=input.nextInt();
System.out.println("enter the process service time:");
table[i][2]=input.nextInt();
}
}
public void print_table(){
for(int i=0;i<size;i++)
{
System.out.println(table[i][0]+" "+table[i][1]+" "+table[i][2]);
}
}
public void proceed(){
int tick=0;
int que_index=0;
int[] queue=new int[size];
for(int i=0;i<=size;i++,tick++) //tick&queue
{
for (int j=0;j<size;j++)//table
{
if(tick==table[j][1]){
queue[que_index]=table[j][0];
que_index++;
}
}
}
System.out.println("Waiting queue according to ids:");
for(int i=0;i<size;i++)
{
System.out.print(queue[i]+" ");
}
System.out.println("\nGraph: ");
for(que_index=0;que_index<size;que_index++)
{
for(int rep=0;rep<table[queue[que_index]-1][2];rep++)
{
System.out.print(queue[que_index]+" ");
}
System.out.println();
}
}
public static void main(String args[]){
int n;
Scanner in =new Scanner(System.in);
System.out.println("Enter number of process:");
n=in.nextInt();
FCFS t1 =new FCFS(n);
t1.enter_table();
t1.print_table();
t1.proceed();
}
}