Question

implement a program, which allow you to evaluate and compare different scheduling algorithms. List of implemented...

implement a program, which allow you to evaluate and compare different scheduling algorithms. List of implemented algorithms for evaluation should include FCFS algorithm and at least one from the following:

-SJF – preemptive and non-preemptive

-Priority scheduling – preemptive and non-preemptive

-RR

-Multilevel feedback queue

Your program should be able to work in two different modes: “Single algorithm performance evaluation” and “Algorithm comparing”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

// Class RoundRobin definition

class RoundRobin

{

// Scanner class object created to accept data

Scanner keyboard = new Scanner(System.in);

int[] burstTime, remainingTime, waitingTime, turnAroundTime;

int numberOfProcess, quantum;

float totalWT = 0, totalTAT = 0;

int flag = 0;

  

// Method to accept data

void acceptData()

{

// Accepts number of processes

System.out.print("Enter the no of process: ");

numberOfProcess = keyboard.nextInt();

// Dynamically allocates memory for all the arrays

burstTime = new int[numberOfProcess];

waitingTime = new int[numberOfProcess];

turnAroundTime = new int[numberOfProcess];

remainingTime = new int[numberOfProcess];

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

{

// Accepts burst time for each process

System.out.print("Enter burst time of P" + (c + 1) + ": ");

burstTime[c] = remainingTime[c] = keyboard.nextInt();

}// End of for loop

// Accepts time quantum

System.out.print("Enter Time Quantum: ");

quantum = keyboard.nextInt();

}// End of method

  

// Method to implement Round Robin algorithm

void RRScheduling()

{

// Loops till flag is not 1

do

{

// Initializes flag to zero

flag = 0;

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

{

// Checks if remaining time of process c is greater than or equals to time quantum

if(remainingTime[c] >= quantum)

{

// Displays each process and its remaining time

System.out.print("P"+(c + 1)+ " -> " + "\t");

// Loops till number of process

for(int d = 0; d < numberOfProcess; d++)

{

// Checks if d value is equals to c

if(d == c)

// Update the remaining time of process c

// by subtract the time quantum from remaining time of process c

remainingTime[c] = remainingTime[c] - quantum;

// Otherwise checks if the remaining time of process d is greater than zero

else if(remainingTime[d] > 0)

// Update the waiting time of process d

// by adding waiting time of process d with time quantum

waitingTime[d] += quantum;

}// End of inner for loop

}// End of if condition

// Otherwise checks remaining time of process c is greater than zero

else if(remainingTime[c] > 0)

{

// Displays each process and its remaining time

System.out.print("P"+(c + 1)+ " -> " + "\t");

// Loops till number of process

for(int d = 0; d < numberOfProcess; d++)

{

// Checks if d value is equals to c

if(d == c)

// Set the remaining time of process c to zero

remainingTime[c] = 0;

// Otherwise checks if the remaining time of process d is greater than zero

else if(remainingTime[d] > 0)

// Update the waiting time of process d

// by adding remaining time of process c with time quantum

waitingTime[d] += remainingTime[c];

}// End of inner for loop

}// End of else if condition

}// End of outer for loop

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

// Checks if the remaining time of process c is greater than zero

if(remainingTime[c] > 0)

// Set the flag to one

flag = 1;

}while(flag == 1); // End of do - while loop

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

// Calculates turn around time of each process

turnAroundTime[c] = waitingTime[c] + burstTime[c];

}// End of method

  

// Method to display processes information

void display()

{

// Displays the heading

System.out.println("\nProcess\tBurst\tWaiting\tTurnaround");

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

{

// Displays process number, burst time, waiting time and turn around time

System.out.println("P" + (c + 1) + "\t" + burstTime[c] + "\t"+waitingTime[c] + "\t" + turnAroundTime[c]);

// Calculates total waiting time

totalWT += waitingTime[c];

// Calculates total turn around time

totalTAT += turnAroundTime[c];

}// End of for loop

// Calculates and displays average waiting time and average turn around time

System.out.printf("%nAverage waiting time: %f", (totalWT / numberOfProcess));

System.out.printf("%nAverage Turnaround time: %f", (totalTAT / numberOfProcess));

}// End of method

}// End of class

// Class FCFS definition

class FCFS

{

// Method to implement FCFS

public void FCFSScheduling()

{

// Scanner class object created

Scanner in = new Scanner(System.in);

// To store number of process

int numberOfProcess;

float totalWT = 0, totalTAT = 0;

// Accepts number of processes from the user

System.out.print("Enter number of processes: ");

numberOfProcess = in.nextInt();

// Dynamically allocates memory for burstTime array

int burstTime[] = new int[numberOfProcess];

System.out.print("Enter burst time");

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

{

// Accepts burst time for each process

System.out.print("Burst time for P" + (c + 1) + " = ");

burstTime[c ] =in.nextInt();

}// End of for loop

// Dynamically allocates memory for waitingTime array

int waitingTime[] = new int[numberOfProcess];

waitingTime[0] = 0;

// Loops till number of process

for(int c = 1; c < numberOfProcess; c++)

{

// Calculates waiting time of each process

waitingTime[c] = burstTime[c - 1] + waitingTime[c - 1];

// Calculates total waiting time

totalWT += waitingTime[c];

}// End of for loop

// Dynamically allocates memory for turnAroundTime array

int turnAroundTime[] = new int[numberOfProcess];

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

{

// Calculates turn around time

turnAroundTime[c] = burstTime[c] + waitingTime[c];

// Calculates total turn around time

totalTAT += turnAroundTime[c];

}// End of for loop

// Displays heading

System.out.println("Process\tBurst time\tWaiting time\tTurn Around time");

// Loops till number of process

for(int c = 0; c < numberOfProcess; c++)

{

// Displays each process number, burst time, waiting time and turn around time

System.out.println("P" + (c + 1) + "\t\t" + burstTime[c] + "\t\t" + waitingTime[c] + "\t\t"+turnAroundTime[c]);

}// End of for loop

System.out.printf("%nAverage Waiting time = %f", totalWT / numberOfProcess);

System.out.printf("%nAverage Turn Around time = %f", totalTAT / numberOfProcess);

}// End of for loop

}// End of class

// Driver class CompareFCFSAndRR definition

public class CompareFCFSAndRR

{

// main method definition

public static void main(String[] args)

{

System.out.println("\t\tFCFS");

// Creates an object of FCFS class

FCFS fcfs = new FCFS();

// Calls the method to implement FCFS scheduling

fcfs.FCFSScheduling();

System.out.println("\n\n\t\tRR");

// Creates an object of RoundRobin class

RoundRobin rr = new RoundRobin();

// Calls the method to accept data

rr.acceptData();

// Calls the method to implement RR scheduling

rr.RRScheduling();

// Calls the method to display result

rr.display();   

}// End of main method

}// End of class

Sample Run:

FCFS

Enter number of processes: 3

Enter burst timeBurst time for P1 = 10

Burst time for P2 = 7

Burst time for P3 = 5

Process Burst time Waiting time Turn Around time

P1 10 0 10

P2 7 10 17

P3 5 17 22

Average Waiting time = 9.000000

Average Turn Around time = 16.333334

RR

Enter the no of process: 3

Enter burst time of P1: 10

Enter burst time of P2: 7

Enter burst time of P3: 5

Enter Time Quantum: 3

P1 -> P2 -> P3 -> P1 -> P2 -> P3 -> P1 -> P2 -> P1 ->

Process Burst Waiting Turnaround

P1 10 12 22

P2 7 14 21

P3 5 12 17

Average waiting time: 12.666667

Average Turnaround time: 20.000000

Add a comment
Know the answer?
Add Answer to:
implement a program, which allow you to evaluate and compare different scheduling algorithms. List of implemented...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight...

    Implement the following 3 CPU scheduling algorithms Simulate and evaluate each with the set of eight processes below. Use any programming language. The program listing should be submitted with the report. FCFS (First Come First Serve) non-preemptive (partial results provided) SJF non-preemptive MLFQ Multilevel Feedback Queue (absolute priority in higher queues)             Queue 1 uses RR scheduling with Tq = 5             Queue 2 uses RR scheduling with Tq = 10             Queue 3 uses FCFS All processes enter first...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • IN OS: Chapter 6 CPU Scheduling • Basic Concepts • Scheduling Criteria – five criteria be...

    IN OS: Chapter 6 CPU Scheduling • Basic Concepts • Scheduling Criteria – five criteria be able to discuss and apply with evidence. • Scheduling Algorithms – FCFS, SJF (optimal), RR (be able to set and justify quantum size), SRTF, Priority - be able to apply each to a set of processes to find the sequence and calculate average wait time (we did a workshop on this). Be able to discuss related to Short Term Scheduler, medium term, long term....

  • Design Principles Canvas Ā 8 pts Question 35 Five batch jobs, A, B, C, D, and...

    Design Principles Canvas Ā 8 pts Question 35 Five batch jobs, A, B, C, D, and E, arrive at a computer system at time 0, 1, 2, 3, 4, respectively. And they have service time of 7.1. 3,5, and 4, respectively. The new jobs arrive a little ahead of the expiration of time slices. For each of the following scheduling algorithms, determine the turnaround time for each process for all jobs. Ignore process switching overhead. • Round robin with a...

  • This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems...

    This assignment requires you to create simulations for different scheduling algorithms commonly employed by operating systems to achieve multiprogramming. All problems in this assignment assume the following: The simulations you will be creating are for a uniprocessor system (single CPU). Processes in these simulations will require CPU bursts of one or more time units followed by I/O bursts of one or more time units. For simplicity’s sake, when more than one process is executing its I/O burst at the same...

  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....

  • scheduling program in C, please help 1 Objectives This programming project is to simulate a few...

    scheduling program in C, please help 1 Objectives This programming project is to simulate a few CPU scheduling policies discussed in the class. You will write a C program to implement a simulator with different scheduling algorithms. The simulator selects a task to run from ready queue based on the scheduling algorithm. Since the project intends to simulate a CPU scheduler, so it does not require any actual process creation or execution. When a task is scheduled, the simulator will...

  • In this assessment, you are required to program an Algorithm-based agent to solve a real-world, which is a challenging case study. This assessment is done individually, and you are required to submit programs and supporting documents in report format. Ple

    You are required to create a robot path planner that is able to find an optimal path to navigate an environment and reach a target. By completing this assessment, you will show your skills on leveraging the best algorithm to solve a simplified real-world problem.The maze can be seen in the image below. It can be seen that there are 12 rows and 24 columns, meaning there is a total of 288 blocks on the map. There are four different...

  • program in python Randomness can be used to improve the performance of deterministic algorithms which need...

    program in python Randomness can be used to improve the performance of deterministic algorithms which need to make many choices. Rather than repeatedly making fixed, hard-coded choices, a pseudorandom number generator can be used to make dynamic, unbiased choices. If the benefits of "good" choices outweigh the costs of "bad" choices, a random selection of good and bad choices can improve the performance of an algorithm Let us explore this with the QUICKSELECT algorithm. Discovered by the influential computer science...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT