Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have done Java program for Round Robin but im not getting expected output. Not sure what is wrong, please help!!! CODE I DID import

I have done Java program for Round Robin but im not getting expected output. Not sure what is wrong, please help!!!
CODE I DID
import java.util.*;
class Process {
int arrivalTime;
int burstTime;
int priority;
int remainingTime;
int turnaroundTime;
int waitingTime;
String processName;
int completionTime;
Process(String processName, int arrivalTime, int burstTime, int priority)
{
this.processName = processName;
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
this.priority = priority;
this.remainingTime = burstTime;
}
}
public class RR {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of processes (3-10): ");
int n = scanner.nextInt();
int[] arrivalTime = new int[n];
int[] burstTime = new int[n];
int[] priority = new int[n];
int[] turnaroundTime = new int[n];
int[] waitingTime = new int[n];
int totalTurnaroundTime =0;
int totalWaitingTime =0;
for (int i =0; i n; i++){
System.out.println("Enter details for P"+ i +":");
System.out.print("Arrival Time: ");
arrivalTime[i]= scanner.nextInt();
System.out.print("Burst Time: ");
burstTime[i]= scanner.nextInt();
System.out.print("Priority: ");
priority[i]= scanner.nextInt();
}
System.out.print("Enter the time quantum: ");
int quantumTime = scanner.nextInt();
int[] remainingTime = new int[n];
System.arraycopy(burstTime,0, remainingTime, 0, n);
int currentTime =0;
boolean[] finished = new boolean[n];
int finishedCount =0;
System.out.println("
Gantt Chart:");
while (finishedCount n){
boolean foundProcess = false;
for (int i =0; i n; i++){
if (!finished[i] && arrivalTime[i]= currentTime){
foundProcess = true;
if (remainingTime[i]> quantumTime){
System.out.print("| P"+ i +"");
currentTime += quantumTime;
remainingTime[i]-= quantumTime;
} else {
System.out.print("| P"+ i +"");
currentTime += remainingTime[i];
remainingTime[i]=0;
finished[i]= true;
finishedCount++;
}
}
}
if (!foundProcess){
System.out.print("| Idle ");
currentTime++;
}
}
System.out.println("|
Finished
");
System.out.println("| PROCESS NAME | ARRIVAL TIME | BURST TIME |
TURNAROUND TIME | WAITING TIME |");
for (int i =0; i n; i++){
turnaroundTime[i]= currentTime - arrivalTime[i];
waitingTime[i]= turnaroundTime[i]- burstTime[i];
totalTurnaroundTime += turnaroundTime[i];
totalWaitingTime += waitingTime[i];
System.out.printf("| P%d |%d |%d |
%d |%d |
",
i, arrivalTime[i], burstTime[i], turnaroundTime[i],
waitingTime[i]);
}
double averageTurnaroundTime =(double) totalTurnaroundTime / n;
double averageWaitingTime =(double) totalWaitingTime / n;
System.out.println("
Total Turnaround Time: "+ totalTurnaroundTime);
System.out.println("Average Turnaround Time: "+
averageTurnaroundTime);
System.out.println("Total Waiting Time: "+ totalWaitingTime);
System.out.println("Average Waiting Time: "+ averageWaitingTime);
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

What would you do at this point if you were Joe Kang and why?

Answered: 1 week ago

Question

could please someone give me the description of this code

Answered: 1 week ago

Question

In bargaining, does it really matter who makes the first offer?

Answered: 1 week ago