Question

In: Computer Science

Write a JAVA program that implements the following disk-scheduling algorithms: FCFS

Write a JAVA program that implements the following disk-scheduling algorithms:

  1. FCFS

Solutions

Expert Solution

Answer:

Program:

import java.util.*;

public class Fcfs
{
   public static void main(String args[])
   {
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the number of processes:");
       int n = sc.nextInt();
       // array for process ids
       int p_id[] = new int[n];   
       // array for arrival times
       int arr_t[] = new int[n];
       // array for burst times
       int burst_t[] = new int[n];   
       // array for completion times
       int comp_t[] = new int[n];
       // array for turn around times
       int tat[] = new int[n];   
       // array for waiting times
       int wait_t[] = new int[n];
       int temp;
       float avg_wt=0,avg_tat=0;

       for(int i = 0; i < n; i++)
       {
           System.out.print("Enter the process" + (i+1) + "'s arrival time: ");
           arr_t[i] = sc.nextInt();
           System.out.print("Enter the process" + (i+1) + "'s brust time: ");
           burst_t[i] = sc.nextInt();
           p_id[i] = i+1;
       }

       //Performs sorting according to the process arrival times
       for(int i = 0 ; i <n; i++)
       {
           for(int j=0; j < n-(i+1) ; j++)
           {
               if( arr_t[j] > arr_t[j+1] )
               {
                   temp = arr_t[j];
                   arr_t[j] = arr_t[j+1];
                   arr_t[j+1] = temp;
                   temp = burst_t[j];
                   burst_t[j] = burst_t[j+1];
                   burst_t[j+1] = temp;
                   temp = p_id[j];
                   p_id[j] = p_id[j+1];
                   p_id[j+1] = temp;
               }
           }
       }
      
       // Calculating the completion times
       for(int i = 0 ; i < n; i++)
       {
           if( i == 0)
           {  
               comp_t[i] = arr_t[i] + burst_t[i];
           }
           else
           {
               if( arr_t[i] > comp_t[i-1])
               {
                   comp_t[i] = arr_t[i] + burst_t[i];
               }
               else
                   comp_t[i] = comp_t[i-1] + burst_t[i];
           }
           // turnaround time= completion time- arrival time
           tat[i] = comp_t[i] - arr_t[i] ;
           // waiting time= turnaround time- burst time
           wait_t[i] = tat[i] - burst_t[i] ;
           // total waiting time
           avg_wt += wait_t[i] ;
           // total turnaround time
           avg_tat += tat[i] ;   
       }
      
       System.out.println("\nPID ARRIVAL_TIME BURST_TIME COMPLETION TURN_AROUND_TIME WAITING");
       for(int i = 0 ; i< n; i++)
       {
           System.out.println(p_id[i] + " \t " + arr_t[i] + " \t " + burst_t[i] + " \t " + comp_t[i] + " \t " + tat[i] + " \t " + wait_t[i] ) ;
       }
       sc.close();
       // printing average waiting time
       System.out.println("\nAverage Waiting Time: "+ (avg_wt/n));
       // printing average turnaround time
       System.out.println("Average Turnaround Time:"+(avg_tat/n));
   }
}

Program Screenshot(s):

Output:


Related Solutions

IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose. The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head...
Write a program that implements the follow disk scheduling algorithms. You can use C or Java...
Write a program that implements the follow disk scheduling algorithms. You can use C or Java for this assignment. FCFS SSTF SCAN C-SCAN LOOK C-LOOK Your program will service a disk with 5000 cylinders (numbered 0 to 4999). Your program will generate a random initial disk head position, as well as a random series of 1000 cylinder requests, and service them using each of the 6 algorithms listed above. Your program will report the total amount of head movement required...
Outcomes: • Write a Java program that implements linked list algorithms can u also show thee...
Outcomes: • Write a Java program that implements linked list algorithms can u also show thee testing code -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- This is the starter code import java.util.NoSuchElementException; // Put your prologue comments here public class LinkedAlgorithms {       private class Node {        private String data;        private Node next;        private Node(String data) {            this.data = data;            this.next = null;        }    }    public Node head;   ...
List of six process scheduling algorithms (for operating systems): First-Come, First-Served (FCFS) Scheduling Shortest-Job-Next (SJN) Scheduling...
List of six process scheduling algorithms (for operating systems): First-Come, First-Served (FCFS) Scheduling Shortest-Job-Next (SJN) Scheduling Priority Scheduling Shortest Remaining Time Round Robin(RR) Scheduling Multiple-Level Queues Scheduling Compare and contrast the algorithms against one another here. You have at least six algorithms, so this should be an extensive part of the project, and all research based.
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2....
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with di_erent quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the ready queue The simulator needs to...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
Write a C++ program that implements both the recursive binary and mergesort algorithms as described in...
Write a C++ program that implements both the recursive binary and mergesort algorithms as described in zyBooks sections 9.4 and 9.5. Prompt the user for the location of a sequence of numbers, via an external file or data entry by the user. If you choose data entry, prompt the user for the number of values and read them into a data structure of your choice. Then use the mergesort algorithm to sort them in ascending order. Finally, prompt for a...
Task: Write a program that implements several sorting algorithms and use it to demonstrate the comparative...
Task: Write a program that implements several sorting algorithms and use it to demonstrate the comparative performance of the algorithms for a variety of datasets. Background The skeleton program sorting.cpp contains a main function for testing the operation of several sort algorithms over various data sizes and dataset organisations. The program understands the following arguments: -i insertion sort -s selection sort (default) -q quicksort -a (already) sorted dataset -v reverse-sorted dataset -r random dataset (default) -n no sorting x generate...
Write a Java program (use JDBC to connect to the database) that implements the following function...
Write a Java program (use JDBC to connect to the database) that implements the following function (written in pseudo code): (20 points) CALL RECURSION ( GIVENP# ) ; RECURSION: PROC ( UPPER_P# ) RECURSIVE ; DCL UPPER_P# ... ; DCL LOWER_P# ... INITIAL ( ' ' ) ; EXEC SQL DECLARE C CURSOR FOR SELECT MINOR_P# FROM PART_STRUCTURE WHERE MAJOR_P# = :UPPER_P# AND MINOR_P# > :LOWER_P# ORDER BY MINOR_P# ; print UPPER_P# ; DO "forever" ; EXEC SQL OPEN C...
Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter...
Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter 8 of your text. First generate a random page-reference string (this should be 20 entries long) where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms so that the number of page frames goes from 1 to 7 and you must compute the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT