I\'m a beginner in JAVA: The Process Scheduler relies on a scheduling algorithm,
ID: 3715567 • Letter: I
Question
I'm a beginner in JAVA:
The Process Scheduler relies on a scheduling algorithm, based on a specific scheduling policy, to allocate the CPU in the best way to move jobs through the system efficiently. Write a Java program that will simulate the following process scheduling algorithm:
1. First-Come, First-Served (FCFS)
Your Java program should produce tables to presents computed results for each scheduling algorithm as shown in the following sample data for the validation your program’s computed results for each scheduling algorithm.
A) Timeline for First-Come First-Served (FCFS) algorithm: 12 15 18 20 Arrival CPU Start Finish Time Cycle Time Time Turnaround Time Finish Time Arrival Time Job 17-0=7 12 15 18 12 12-1 = 11 15 15-2 13 18 18 3 15 20 20-4 = 16 2 Average Turnaround Time (711 1315 16)/5 62/5 12.4Explanation / Answer
import java.util.Scanner;
class Process{
int startTime=0;
int arrivalTime;
int bursts;
int turnAround;
int phinishTime = 0;
Process(int sub,int bur){
arrivalTime= sub;
bursts = bur;
}
}
class FCFS{
public static void main(String[] args){
int x=0,sum=0;
char y='A';
Scanner s = new Scanner(System.in);
System.out.println("Enter the number of processes:");
int n = s.nextInt();
Process[] myProcess = new Process[n];
for(int i=0;i<n;i++){
System.out.println("Enter Arrival time and bursts: ");
int sub = s.nextInt();
int bur = s.nextInt();
myProcess[i] = new Process(sub,bur);
}
for(int i=0;i<myProcess.length;i++){
x = x+myProcess[i].bursts;
myProcess[i].phinishTime = x;
myProcess[i].turnAround = myProcess[i].phinishTime - myProcess[i].arrivalTime;
System.out.println("Process "+i+":");
System.out.println("Turnaround Completion waiting");
}
myProcess[0].startTime=myProcess[0].arrivalTime;
for(int i=1;i<myProcess.length;i++)
myProcess[i].startTime=myProcess[i-1].phinishTime;
System.out.println(" Job "+" Atrival time "+" CPU Cycle "+ " Start Time "+ "Phinish Time"+ " Turn Around Time ");
for(int i=0;i<myProcess.length;i++)
{
System.out.println(y+" "+myProcess[i].arrivalTime+" "+myProcess[i].bursts+" "+myProcess[i].startTime+" "+myProcess[i].phinishTime+" "+myProcess[i].turnAround);
sum+=myProcess[i].turnAround;
y++;
}
System.out.println("Average Turnaround time:"+sum/myProcess.length);
}
}
output:
run:
Enter the number of processes:
5
Enter Arrival time and bursts:
0 7
Enter Arrival time and bursts:
1 5
Enter Arrival time and bursts:
2 3
Enter Arrival time and bursts:
3 3
Enter Arrival time and bursts:
4 2
Process 0:
Turnaround Completion waiting
Process 1:
Turnaround Completion waiting
Process 2:
Turnaround Completion waiting
Process 3:
Turnaround Completion waiting
Process 4:
Turnaround Completion waiting
Job Atrival time CPU Cycle Start Time Phinish Time Turn Around Time
A 0 7 0 7 7
B 1 5 7 12 11
C 2 3 12 15 13
D 3 3 15 18 15
E 4 2 18 20 16
Average Turnaround time:12
BUILD SUCCESSFUL (total time: 29 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.