Question

In: Computer Science

OPERATING SYSTEMS HOMEWORK: PLEASE CODE IN JAVA with comments & POST SCREENSHOTS OF OUTPUTS SCAN This...

OPERATING SYSTEMS HOMEWORK: PLEASE CODE IN JAVA with comments & POST SCREENSHOTS OF OUTPUTS

  • SCAN This algorithm is performed by moving the R/W head back-and-forth to the innermost and outermost track. As it scans the tracks from end to end, it process all the requests found in the direction it is headed. This will ensure that all track requests, whether in the outermost, middle or innermost location, will be traversed by the access arm thereby finding all the requests. This is also known as the Elevator algorithm.

  • LOOK This algorithm is similar to SCAN algorithm except for the end-to-end reach of each sweep. The R/W head is only tasked to go the farthest location in need of servicing. This is also a directional algorithm, as soon as it is done with the last request in one direction it then sweeps in the other direction.

  • FCFS It is the simplest form of disk scheduling algorithms. The I/O requests are served or processes according to their arrival. The request arrives first will be accessed and served first. Since it follows the order of arrival, it causes the wild swings from the innermost to the outermost tracks of the disk and vice versa . The farther the location of the request being serviced by the read/write head from its current location, the higher the seek time will be.

  • CLOOK Circular LOOK is like a C-SCAN which uses a return sweep before processing a set of disk requests. It does not reach the end of the tracks unless there is a request, either read or write on such disk location similar with the LOOK algorithm.

  • CSCAN This algorithm is a modified version of the SCAN algorithm. C-SCAN sweeps the disk from end-to-end,but as soon it reaches one of the end tracks it then moves to the other end track without servicing any requesting location. As soon as it reaches the other end track it then starts servicing and grants requests headed to its direction. This algorithm improves the unfair situation of the end tracks against the middle tracks

Solutions

Expert Solution

CODE:


// SCAN  algorithm
import java.util.*;
 
class GFG
{
 
static int size = 8;
static int disk_size = 200;
 
static void SCAN(int arr[], int head, String direction)
{
    int seek_count = 0;
    int distance, cur_track;
    Vector<Integer> left = new Vector<Integer>(),
                    right = new Vector<Integer>();
    Vector<Integer> seek_sequence = new Vector<Integer>();
 
    // appending end values
    // which has to be visited
    // before reversing the direction
    if (direction == "left")
        left.add(0);
    else if (direction == "right")
        right.add(disk_size - 1);
 
    for (int i = 0; i < size; i++) 
    {
        if (arr[i] < head)
            left.add(arr[i]);
        if (arr[i] > head)
            right.add(arr[i]);
    }
 
    // sorting left and right vectors
    Collections.sort(left);
    Collections.sort(right);
 
    // run the while loop two times.
    // one by one scanning right
    // and left of the head
    int run = 2;
    while (run-- >0)
    {
        if (direction == "left") 
        {
            for (int i = left.size() - 1; i >= 0; i--) 
            {
                cur_track = left.get(i);
 
                // appending current track to seek sequence
                seek_sequence.add(cur_track);
 
                // calculate absolute distance
                distance = Math.abs(cur_track - head);
 
                // increase the total count
                seek_count += distance;
 
                // accessed track is now the new head
                head = cur_track;
            }
            direction = "right";
        }
        else if (direction == "right") 
        {
            for (int i = 0; i < right.size(); i++) 
            {
                cur_track = right.get(i);
                 
                // appending current track to seek sequence
                seek_sequence.add(cur_track);
 
                // calculate absolute distance
                distance = Math.abs(cur_track - head);
 
                // increase the total count
                seek_count += distance;
 
                // accessed track is now new head
                head = cur_track;
            }
            direction = "left";
        }
    }
 
    System.out.print("Total number of seek operations = "
                        + seek_count + "\n");
 
    System.out.print("Seek Sequence is" + "\n");
 
    for (int i = 0; i < seek_sequence.size(); i++)
    {
        System.out.print(seek_sequence.get(i) + "\n");
    }
}
 
// 
public static void main(String[] args)
{
 
    // request array
    int arr[] = { 176, 79, 34, 60,
                    92, 11, 41, 114 };
    int head = 50;
    String direction = "left";
 
    SCAN(arr, head, direction);
}
}

OUTPUT:

LOOK ALGORITHM:

FCFS ALGORITHM

Implementation of FCFS is given below. Note that distance is used to store absolute distance between head and current track position.

CODE IN JAVA


// FCFS Disk Scheduling algorithm 
class GFG 
{ 
static int size = 8; 
  
static void FCFS(int arr[], int head) 
{ 
    int seek_count = 0; 
    int distance, cur_track; 
  
    for (int i = 0; i < size; i++)  
    { 
        cur_track = arr[i]; 
  
        // calculate absolute distance 
        distance = Math.abs(cur_track - head); 
  
        // increase the total count 
        seek_count += distance; 
  
        // accessed track is now new head 
        head = cur_track; 
    } 
  
    System.out.println("Total number of " +  
                       "seek operations = " +  
                        seek_count); 
  
    // Seek sequence would be the same 
    // as request array sequence 
    System.out.println("Seek Sequence is"); 
  
    for (int i = 0; i < size; i++) 
    { 
        System.out.println(arr[i]); 
    } 
} 
  
//  
public static void main(String[] args)  
{ 
    // request array 
    int arr[] = { 176, 79, 34, 60,  
                  92, 11, 41, 114 }; 
    int head = 50; 
  
    FCFS(arr, head); 
} 
} 

OUTPUT:


Related Solutions

Please show fully functioning Java code and screenshots of outputs. Please separate by 1a and 1b....
Please show fully functioning Java code and screenshots of outputs. Please separate by 1a and 1b. #1. Design a Java JProduct class for a product which implements both cloneable and comparable interfaces The class should have the following private member variables: m_id: an integer that holds the product ID m_name: a string that holds the product name m_wholesaleprice: a double that holds the wholesale price m_retailers: a String array that holds all retailers who sell the product and the class...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h"...
Please comments this C++ code and show screenshots of the outputs main.cpp #include<iostream> #include<vector> #include<string> #include"BST.h" #include"BST.cpp" using namespace std; std::vector<std::string> tokenize(char line[]) {    std::vector<std::string> tok;        std::string word = "";        for (int i = 0; i < strlen(line); i++)        {            if (i == strlen(line) - 1)            {                word += line[i];                tok.push_back(word);                return tok;       ...
Please post screenshots of outputs. Also make sure to use stacks and queues. You will design...
Please post screenshots of outputs. Also make sure to use stacks and queues. You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
This is an intro to java question. Please post with pseudocode and java code. Problem should...
This is an intro to java question. Please post with pseudocode and java code. Problem should be completed using repetition statements like while and selection statements. Geometry (10 points) Make API (API design) Java is an extensible language, which means you can expand the programming language with new functionality by adding new classes. You are tasked to implement a Geometry class for Java that includes the following API (Application Programming Interface): Geometry Method API: Modifier and Type Method and Description...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.
JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in...
JAVA CODE BEGINNER , Please use comments to explain, please Repeat the calorie-counting program described in Programming Project 8 from Chapter 2. This time ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the female formula to calculate calories if “W” is entered. Output the number of chocolate bars to consume as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT