THINK FIRST·CODE LATER

← All labs

Disk-scheduling simulator

Problem

Input: algorithm (FCFS, SSTF, SCAN, CSCAN, LOOK, CLOOK), the last cylinder max (cylinders 0 … max), the initial head position, the initial direction (up or down), then the request queue.

Rules:

  • SSTF: nearest request next; ties → the lower cylinder.
  • SCAN: serve requests in the current direction, go to the end (0 or max) only if requests remain on the other side, then reverse.
  • LOOK: like SCAN, but reverse at the last request.
  • CSCAN: serve in the current direction, go to the end, jump to the other end (the jump counts as head movement), and continue in the same direction.
  • CLOOK: like CSCAN, but go only to the last request and jump directly to the farthest request on the other side (the jump counts).
  • A request at the head's current position counts as being on the up side.

Print Order: 53 -> 65 -> … (starting at the head) and SSTF total head movement: 236 cylinders.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os11-1-data-1.txt

FCFS 199 53 down 98 183 37 122 14 124 65 67
What your program must print for os11-1-data-1.txt
Order: 53 -> 98 -> 183 -> 37 -> 122 -> 14 -> 124 -> 65 -> 67
FCFS total head movement: 640 cylinders

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os11-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content os11-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.