Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you get the throughout put for the Round Robin program ? import java.awt.

ID: 3751849 • Letter: H

Question

How do you get the throughout put for the Round Robin program ?

import java.awt.image.BufferStrategy;

import java.util.Random;

import java.util.Scanner;

import java.util.Scanner.*;

public class RoundRobin {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

int quantum, sum = 0;

float average_waitingtime = 0;

float average_turnaroundtime = 0;

float average_responsetime = 0;

System.out.println(" ------------------------------------------");

System.out.println(" ** Round robin CPU Scheduling Algorithm **");

System.out.println(" ------------------------------------------");

System.out.println("Enter number of process:");

int n = sc.nextInt();

int burst_time[] = new int[n];

int waiting_time[] = new int[n];

int turnaround_time[] = new int[n];

int array[] = new int[n];

// System.out.println(" Please Enter brust Time:");

// for (int i = 0; i < n; i++) {

// System.out.println(" Please Enter brust Time for process: " + (i + 1));

// burst_time[i] = sc.nextInt();

// }

Random rand = new Random();

for(int i = 0; i< n ; i++) {

burst_time[i] = rand.nextInt(25);

}

System.out.println(" Please Enter Time quantum:");

quantum = sc.nextInt();

for (int i = 0; i < n; i++)

array[i] = burst_time[i];

for (int i = 0; i < n; i++)

waiting_time[i] = 0;

do {

for (int i = 0; i < n; i++) {

if (burst_time[i] > quantum) {

burst_time[i] -= quantum;

for (int j = 0; j < n; j++) {

if ((j != i) && (burst_time[j] != 0))

waiting_time[j] += quantum;

}

} else {

for (int j = 0; j < n; j++) {

if ((j != i) && (burst_time[j] != 0))

waiting_time[j] += burst_time[i];

}

burst_time[i] = 0;

}

}

sum = 0;

for (int k = 0; k < n; k++)

sum = sum + burst_time[k];

} while (sum != 0);

for (int i = 0; i < n; i++)

turnaround_time[i] = waiting_time[i] + array[i];

System.out.println(" process BurstTime WaitingTime TurnAroundTime");

for (int i = 0; i < n; i++) {

System.out.println(

"process" + (i + 1) + " " + array[i] + " " + waiting_time[i] + " " + turnaround_time[i]);

}

for (int j = 0; j < n; j++) {

average_waitingtime += waiting_time[j];

}

for (int j = 0; j < n; j++) {

average_turnaroundtime += turnaround_time[j];

}

for(int j = 0; j < n;j++) {

average_responsetime += waiting_time[j] + turnaround_time[j];

}

System.out.println(" The average waiting time is:" + (average_waitingtime / n));

System.out.println(" The Average turn around time is: " + (average_turnaroundtime / n));

System.out.println(" The average response time is: " + (average_responsetime / n));

}

}

Here is my code

Explanation / Answer

Throughput :- Number of processes completed their execution per unit time.

Formulae:- Throughput = Number of Processes / (Total Time)

Total Time is the time required to execute all the processes.

So in your code number_of_processes is n and I've calculated Total Time which is saved into the variable Total_Time.

Then calculated throughput( n / Total_Time) and saved into the variavble "Throughput".

Now, you see your modified code. You can understand what I did.

import java.awt.image.BufferStrategy;

import java.util.Random;

import java.util.Scanner;

import java.util.Scanner.*;

public class RoundRobin
{

public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int quantum, sum = 0;
float average_waitingtime = 0;
float average_turnaroundtime = 0;
float average_responsetime = 0;
System.out.println(" ------------------------------------------");
System.out.println(" ** Round robin CPU Scheduling Algorithm **");
System.out.println(" ------------------------------------------");
System.out.println("Enter number of process:");
int n = sc.nextInt();
int burst_time[] = new int[n];
int waiting_time[] = new int[n];
int turnaround_time[] = new int[n];
int array[] = new int[n];

// System.out.println(" Please Enter brust Time:");

// for (int i = 0; i < n; i++) {

// System.out.println(" Please Enter brust Time for process: " + (i + 1));

// burst_time[i] = sc.nextInt();

// }

Random rand = new Random();
for(int i = 0; i< n ; i++)
{
burst_time[i] = rand.nextInt(25);
}
System.out.println(" Please Enter Time quantum:");
quantum = sc.nextInt();
for (int i = 0; i < n; i++)
array[i] = burst_time[i];

//I'm calculating the total burst time and savings into the variable Total_Time
int Total_Time=0;
for(int i = 0; i < n ; i++)
Total_Time = Total_Time + burst_time[i];
System.out.println(" The Total_Time is: " + Total_Time);

for (int i = 0; i < n; i++)
waiting_time[i] = 0;
do {
for (int i = 0; i < n; i++)
{
if (burst_time[i] > quantum)
{
burst_time[i] -= quantum;
for (int j = 0; j < n; j++)
{
if ((j != i) && (burst_time[j] != 0))
waiting_time[j] += quantum;
}
}
else
{
for (int j = 0; j < n; j++)
{
if ((j != i) && (burst_time[j] != 0))
waiting_time[j] += burst_time[i];
}
burst_time[i] = 0;
}
}

sum = 0;
for (int k = 0; k < n; k++)
sum = sum + burst_time[k];
}while (sum != 0);
for (int i = 0; i < n; i++)
turnaround_time[i] = waiting_time[i] + array[i];
System.out.println(" process BurstTime WaitingTime TurnAroundTime");
for (int i = 0; i < n; i++)
{
System.out.println("process" + (i + 1) + " " + array[i] + " " + waiting_time[i] + " " + turnaround_time[i]);
}
for (int j = 0; j < n; j++)
{
average_waitingtime += waiting_time[j];
}
for (int j = 0; j < n; j++)
{
average_turnaroundtime += turnaround_time[j];
}
for(int j = 0; j < n;j++)
{
average_responsetime += waiting_time[j] + turnaround_time[j];
}
System.out.println(" The average waiting time is:" + (average_waitingtime / n));
System.out.println(" The Average turn around time is: " + (average_turnaroundtime / n));
System.out.println(" The average response time is: " + (average_responsetime / n));

//Newly Added Code
//Calculating Throughput
float Throughput = (float) n / Total_Time;
System.out.println(" The Total_Time is: " + Total_Time);
System.out.println(" n is: " + n);
//Printing Throughput

System.out.println(" The Throughput(n/Total_Time) is: " + Throughput);
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote