-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLab1.java
More file actions
149 lines (118 loc) · 5.52 KB
/
Lab1.java
File metadata and controls
149 lines (118 loc) · 5.52 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
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
package process_scheduling_algorithm;
import java.util.*;
public class Lab1 {
public static int[] CreateRandom() {
int min =2;
int max =10;
max-=min;
int m = (int) (Math.random()*++max)+min;
int[] mas = new int[m];
System.out.println("The number of " + m + " processes was created");
for (int i = 0; i < mas.length; i++) {
double k = Math.random();
int l = (int) (k * 100);
System.out.println("The burst time of the process [" + i + "] is " + l);
mas[i] = l;
}
return mas;
}
public static int[] procn(int mas[])
{
int n = mas.length;
int[] k = new int[n];
for(int i=1;i<=n;i++)
{
k[i-1]=i;
}
return k;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
outer1:
while (true) {
System.out.println("Pls, enter the number of the operation you want to do");
System.out.println("1. Create a new set of processes");
System.out.println("2. Conclusion");
System.out.println("0. Quit");
int choice = in.nextInt();
double fifo_wt=0;
double sjf_wt=0;
double rr_wt=0;
switch (choice) {
case 1: {
int[] mas = CreateRandom();
outer:
while (true) {
{
System.out.println("------------------------------------------------------");
System.out.println("Pls, enter the number of the operation you want to do");
System.out.println("1. Calculate the average waiting time using FIFO algorithm");
System.out.println("2. Calculate the average waiting time using process_scheduling_algorithm.SJF algorithm");
System.out.println("3. Calculate the average waiting time using process_scheduling_algorithm.RoundRobin algorithm");
System.out.println("4. Previous ");
int choice1 = in.nextInt();
switch (choice1) {
case 1: {
System.out.println(FCFS.FCFS(mas));
continue outer;
}
case 2: {
System.out.println(SJF.SJF(mas));
continue outer;
}
case 3: {
int[] proc = procn(mas);
int n = mas.length;
System.out.println("Pls enter the quantum time");
int quantum = in.nextInt();
System.out.println(RoundRobin.findavgTime(proc, n, mas, quantum));
continue outer;
}
case 4:{
continue outer1;
}
}
}
}
}
case 0: {
break;
}
case 2:{
outer3: while (true){
System.out.println("1. FIFO");
System.out.println("2. process_scheduling_algorithm.SJF");
System.out.println("3. process_scheduling_algorithm.RoundRobin");
int choice2 = in.nextInt();
switch(choice2)
{
case 1:{
System.out.println("------");
System.out.println("It is most suitable for long, time-consuming CPU processes;\n Bad usage of CPU and device I/o;\n The average waiting time varies greatly.");
System.out.println("------");
break outer3;
}
case 2:{
System.out.println("------");
System.out.println("Processes already running on the CPU are pushed out by the closest job to completion;\n Less overall turnaround time of the process;\nLess CPU waiting time");
System.out.println("------");
break outer3;
}
case 3:{
System.out.println("------");
System.out.println("If q(tends to ∞), then the RR algorithm degenerates to FIFO;\n" +
"If q is small (but does not tend to 0, otherwise the PC will only switch processes and no longer perform anything at all), then everything is fine;\n" +
"No starvation;\n" +
"There is a high responsiveness of the system;\n" +
"Equal distribution of time;\n" +
"If q is less than the time it takes to switch context, then the manager will be ineffective.");
System.out.println("------");
break outer3;
}
}
}
}
}
}
}
}