-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
156 lines (114 loc) · 5.62 KB
/
Main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int numOfProcesses;
int arrivalTime;
int Qnumber;
String nameOfProcess;
int contextSwitchTime;
int RRtime;
int priorityTime;
ArrayList<Process> process = new ArrayList<Process>();
Scanner input = new Scanner(System.in);
System.out.println("please choose the algorithm you want to use" );
System.out.println("1-SJF ");
System.out.println("2-Round Robin");
System.out.println("3-Preemptive Priority");
System.out.println("4-MultiLevel ");
int choice = input.nextInt();
if(choice == 1)
{
System.out.println("Please enter number of processes ");
numOfProcesses = input.nextInt();
for (int i = 0; i < numOfProcesses; i++) {
System.out.println("Please enter name of process " + (i+1));
nameOfProcess = input.next();
System.out.println("Please enter arrival time of process " + nameOfProcess);
arrivalTime = input.nextInt();
System.out.println("Please enter burst time of process " + nameOfProcess);
int burstTime = input.nextInt();
System.out.println("Please enter Queue number that the process will enter ");
Qnumber = input.nextInt();
System.out.println("Please enter priority time ");
priorityTime = input.nextInt();
Process temp = new Process(nameOfProcess,arrivalTime,Qnumber,burstTime,priorityTime);
process.add(temp);
}
System.out.println("Please enter context switching time ");
contextSwitchTime = input.nextInt();
SJF sjf = new SJF(process, contextSwitchTime);
}
else if (choice == 2)
{
System.out.println("Please enter number of processes ");
numOfProcesses = input.nextInt();
for (int i = 0; i < numOfProcesses; i++) {
Process p = new Process();
System.out.println("Please enter name of process " + (i+1));
nameOfProcess = input.next();
p.setProcessName(nameOfProcess);
System.out.println("Please enter arrival time of process " + nameOfProcess);
p.setArrivalTime(input.nextInt());
System.out.println("Please enter burst time of process " + nameOfProcess);
int t = input.nextInt();
p.setBurstTime(t);
p.setRemainingTime(t);
process.add(p);
}
System.out.println("Please enter context switching time ");
contextSwitchTime = input.nextInt();
System.out.println("Please enter Round Robin time quantum ");
RRtime = input.nextInt();
RoundRobin RR = new RoundRobin(RRtime , contextSwitchTime , process);
RR.processesExecution();
}
else if (choice == 3)
{
System.out.println("Please enter number of processes ");
numOfProcesses = input.nextInt();
for (int i = 0; i < numOfProcesses; i++) {
System.out.println("Please enter name of process " + (i+1));
nameOfProcess = input.next();
System.out.println("Please enter arrival time of process " + nameOfProcess);
arrivalTime = input.nextInt();
System.out.println("Please enter burst time of process " + nameOfProcess);
int burstTime = input.nextInt();
System.out.println("Please enter Queue number that the process will enter ");
Qnumber = input.nextInt();
System.out.println("Please enter priority time ");
priorityTime = input.nextInt();
Process temp = new Process(nameOfProcess,arrivalTime,Qnumber,burstTime,priorityTime);
process.add(temp);
}
System.out.println("Please enter context switching time ");
contextSwitchTime = input.nextInt();
preemptivePriority priority= new preemptivePriority();
priority.run(process, contextSwitchTime);
}
else if (choice == 4)
{
System.out.println("Please enter number of processes ");
numOfProcesses = input.nextInt();
for (int i = 0; i < numOfProcesses; i++) {
Process p = new Process();
System.out.println("Please enter name of process " + (i+1));
nameOfProcess = input.next();
p.setProcessName(nameOfProcess);
System.out.println("Please enter arrival time of process " + nameOfProcess);
p.setArrivalTime(input.nextInt());
System.out.println("Please enter burst time of process " + nameOfProcess);
int t = input.nextInt();
p.setBurstTime(t);
p.setRemainingTime(t);
System.out.println("Please enter Queue number that the process will enter ");
p.setQueueNumber(input.nextInt());
process.add(p);
}
System.out.println("Please enter Round Robin time quantum ");
RRtime = input.nextInt();
MultiLevel ML = new MultiLevel(process,RRtime);
ML.scheduling();
}
}
}