-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosproject.java
More file actions
176 lines (168 loc) · 6.96 KB
/
osproject.java
File metadata and controls
176 lines (168 loc) · 6.96 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package project;
import java.util.List;
import java.util.Arrays;
public class osproject {
//function for the first come first serve
public static void fcfs(String jobnumber[], int jobtime[]) {
int n = jobnumber.length;
int starttime[] = new int[n]; //create an array for the start time
starttime[0] = 0; //set the Initial start time equals to 0
int endtime[] = new int[n]; //create an array for the end time
endtime[0]=jobtime[0]; // set the Initial end time equals to the first job completion time
for(int i=1; i<jobnumber.length;i++) { //calculate for the end time
endtime[i] = endtime[i-1] + jobtime[i];
starttime[i] = endtime[i-1]; //calculate for the start time
}
int totalturnaroundtime = 0; //Initial the total turn around time equals 0
for(int i=0; i<jobtime.length; i++) {
totalturnaroundtime = totalturnaroundtime + endtime[i]; //calculate for the total turn around time
}
System.out.println("________________________________________________________________________");
System.out.printf("|\tJob#\t| Start time\t| Endtime\t|\tJob completion \t|\n");
for(int i = 0; i<jobnumber.length; i++) {
System.out.printf("|\t"+jobnumber[i]+"\t|");
System.out.printf("\t%d\t|",starttime[i]);
System.out.printf("\t%d\t|",endtime[i]);
System.out.printf("job "+jobnumber[i]+" completed at %d\t|\n",endtime[i]);
}
System.out.println("________________________________________________________________________");
float avgturnaroundtime = (float) totalturnaroundtime / (float) n;
System.out.print("the average turnaround time is: ");
System.out.print(avgturnaroundtime+"\n");
}
//function for the shortest job first
public static void shortestjobfirst(String jobnumber[], int jobtime[]) {
int n = jobnumber.length;
int temp;
for(int i=1; i<n;i++) { //sorting the array
for(int j=i; j>0;j--) {
if(jobtime[j]<jobtime[j-1]) {
temp = jobtime[j];
jobtime[j] = jobtime[j-1];
jobtime[j-1]= temp;
String jobnumbertemp = jobnumber[j];//sorting the job number's array
jobnumber[j] = jobnumber[j-1];
jobnumber[j-1] = jobnumbertemp;
}
}
}
int starttime[] = new int[n]; //create an array for the start time
starttime[0] = 0; //set the Initial start time equals to 0
int endtime[] = new int[n]; //create an array for the end time
endtime[0]=jobtime[0]; // set the Initial end time equals to the first job completion time
for(int i=1; i<jobnumber.length;i++) { //calculate for the end time
endtime[i] = endtime[i-1] + jobtime[i];
starttime[i] = endtime[i-1]; //calculate for the start time
}
int totalturnaroundtime = 0; //Initial the total turn around time equals 0
for(int i=0; i<jobtime.length; i++) {
totalturnaroundtime = totalturnaroundtime + endtime[i]; //calculate for the total turn around time
}
System.out.println("________________________________________________________________________");
System.out.printf("|\tJob#\t| Start time\t| Endtime\t|\tJob completion \t|\n");
for(int i = 0; i<jobnumber.length; i++) {
System.out.printf("|\t"+jobnumber[i]+"\t|");
System.out.printf("\t%d\t|",starttime[i]);
System.out.printf("\t%d\t|",endtime[i]);
System.out.printf("job "+jobnumber[i]+" completed at %d\t|\n",endtime[i]);
}
System.out.println("________________________________________________________________________");
float avgturnaroundtime = (float) totalturnaroundtime / (float) n;
System.out.print("the average turnaround time is: ");
System.out.print(avgturnaroundtime+"\n");
}
public static void RR5(String jobnumber[], int jobtime[]) {
int n = jobtime.length;
int completiontime[] = new int[n];
int starttime = 0;
int endtime = 0;
System.out.println("________________________________________________________________________");
System.out.printf("|\tJob#\t| Start time\t| Endtime\t|\tJob completion \t|\n");
int totalfinishtime = 0;
for(int i =0; i<n;i++) {
totalfinishtime = totalfinishtime + jobtime[i];
}
while(totalfinishtime>-5000) {
for(int i = 0; i<jobtime.length; i++) {
if(jobtime[i]<=5 && jobtime[i]>0) {
System.out.printf("\n|\t"+jobnumber[i]+"\t|");
System.out.printf("\t%d\t|",starttime);
endtime = endtime + jobtime[i];
starttime = endtime;
completiontime[i]=endtime;
System.out.printf("\t%d\t|",endtime);
jobtime[i]= jobtime[i]-endtime;
if(jobtime[i]<=0)
System.out.printf("job "+jobnumber[i]+" completed at %d\t|",endtime);
totalfinishtime = totalfinishtime - endtime;
}
else if(jobtime[i]>5) {
System.out.printf("|\n\t"+jobnumber[i]+"\t|");
System.out.printf("\t%d\t|",starttime);
endtime = endtime +5;
starttime = endtime;
System.out.printf("\t%d\t",endtime);
jobtime[i] = jobtime[i]-5;
}
else if(jobtime[i]<=0) {
continue;
}}
totalfinishtime = totalfinishtime -5;
}
int totalturnaroundtime = 0;
for(int i=0; i<n; i++) {
totalturnaroundtime = totalturnaroundtime + completiontime[i];
}
float avgturnaroundtime = (float)totalturnaroundtime / (float)n;
System.out.println("");
System.out.println("the average turnaround time is: ");
System.out.print(avgturnaroundtime);
}
public static void RR2(String jobnumber[], int jobtime[]) {
int n = jobtime.length;
int completiontime[] = new int[n];
int starttime = 0;
int endtime = 0;
System.out.println("________________________________________________________________________");
System.out.printf("|\tJob#\t| Start time\t| Endtime\t|\tJob completion \t|\n");
int totalfinishtime = 0;
for(int i =0; i<n;i++) {
totalfinishtime = totalfinishtime + jobtime[i];
}
while(totalfinishtime>-5000) {
for(int i = 0; i<jobtime.length; i++) {
if(jobtime[i]<=2 && jobtime[i]>0) {
System.out.printf("\n|\t"+jobnumber[i]+"\t|");
System.out.printf("\t%d\t|",starttime);
endtime = endtime + jobtime[i];
starttime = endtime;
completiontime[i]=endtime;
System.out.printf("\t%d\t|",endtime);
jobtime[i]= jobtime[i]-endtime;
if(jobtime[i]<=0)
System.out.printf("job "+jobnumber[i]+" completed at %d\t|",endtime);
totalfinishtime = totalfinishtime - endtime;
}
else if(jobtime[i]>2) {
System.out.printf("|\n\t"+jobnumber[i]+"\t|");
System.out.printf("\t%d\t|",starttime);
endtime = endtime +2;
starttime = endtime;
System.out.printf("\t%d\t",endtime);
jobtime[i] = jobtime[i]-2;
}
else if(jobtime[i]<=0) {
continue;
}}
totalfinishtime = totalfinishtime -2;
}
int totalturnaroundtime = 0;
for(int i=0; i<n; i++) {
totalturnaroundtime = totalturnaroundtime + completiontime[i];
}
float avgturnaroundtime = (float)totalturnaroundtime / (float)n;
System.out.println("");
System.out.println("the average turnaround time is: ");
System.out.print(avgturnaroundtime);
}
}