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

Please write in JAVA . Write a program that implements the following disk-schedu

ID: 3851449 • Letter: P

Question

Please write in JAVA. Write a program that implements the following disk-scheduling algorithms: FCFS SSTF SCAN C-SCAN LOOK C-LOOK

There is similar code online but please do not submit if it is incorrect. I asked this question and someone gave me code that did not work. Include lots! of comments and add screenshots of output of it working on your machine. Please don't waste my question by answering with the wrong information.

Your program will service a disk with n cylinders numbered 0 to n-1. The program will read a data file (“input.txt”). The first entry in the data file is the number of cylinders for your disk. The next entry is the cylinder number the disk position at the beginning of the simulation. Next, comes a line with a string of numbers representing the numbers of cylinders with I/O requests and service them according to each of the algorithms listed above. It will output the total amount of head movement required by each algorithm. The output should look something like the following:

For FCFS, the total head movement was xxx cylinders.

For SSTF, the total head movement was xxx cylinders.

For SCAN, the total head movement was xxx cylinders.

For C-SCAN, the total head movement was xxx cylinders.

For LOOK, the total head movement was xxx cylinders.

For C-LOOK, the total head movement was xxx cylinders.

The data in this first set is that used on pages 447 – 451 in your text and may be used to check your code. Then your program will read a second similar set of data from the same file and run that. Note that the data second set has different number of cylinders. Please make extensive comments explaining as much as possible Do any of the algorithms look especially good or bad? Data will be posted below.

* Data *

Explanation / Answer

import java.util.*;

public class Scheduling {

public static void fcfs(int c[], int hm[], int hs, int n) {
int total = 0;
int flag = hs;
for (int i = 0; i < n; i++) {
if (c[i] > flag) {
hm[i] = c[i] - flag;
} else {
hm[i] = flag - c[i];
}
flag = c[i];
}
for (int i = 0; i < n; i++) {
total = total + hm[i];
}
System.out.println("The total no of cylinders traversed during disk movement is:" + total);
}

public static void sstf(int headPos, int ci[]) {
ArrayList<Integer> data = new ArrayList<Integer>();
for(int i=0;i<ci.length;i++) {
data.add(ci[i]);
}
int total = 0;
while (data.size() > 0) // SSTF
{
int nearestPos = 0;
for (int j = 1; j < data.size(); j++) // find next closest position
{
if (Math.abs(headPos - data.get(j).intValue())
< Math.abs(headPos - data.get(nearestPos).intValue())) {
nearestPos = j; // closest position index
}
}
total += Math.abs(headPos - data.get(nearestPos).intValue());
headPos = data.get(nearestPos).intValue(); // reposition the head

System.out.print(" - " + headPos);
data.remove(nearestPos); // remove processed request
}

System.out.println("The total no of cylinders traversed during disk movement is:" + total);
}
public static void scan(int c[], int currentPos, int n){
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i=0; i<c.length; i++){
list.add(c[i]);
}

int direction = 1;
int sum = 0;
while(!list.isEmpty()){
currentPos += direction;
sum++;
if(list.contains(new Integer(currentPos))){
list.remove(new Integer(currentPos));
}
if(currentPos == n){
sum += n;
currentPos = -1;
}
}
System.out.println("The total no of cylinders traversed during disk movement is:" + sum);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter no of cylinders: ");
int n = sc.nextInt();
int c[] = new int[n];
int hm[] = new int[n];
System.out.println("Enter the cylinder no.");
for (int i = 0; i < n; i++) {
c[i] = sc.nextInt();
}
System.out.println("enter head start");
int hs = sc.nextInt();
fcfs(c, hm, hs, n);
sstf(hs,c);
scan(c,hs,n);
}
}