Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA - please help with the error regarding the bold line below. I am getting the following error: The type ProcessSchedulingSimulator.Process does not define getProcessArrivalTime(T)

JAVA - please help with the error regarding the bold line below. I am getting the following error:

The type ProcessSchedulingSimulator.Process does not define getProcessArrivalTime(T) that is applicable here

image text in transcribed

Full Code:

import java.util.*;

public class ProcessSchedulingSimulator {

// Process table with one entry per process containing a process sequence number,

// the process class, its process arrival time and its current status (READY, RUNNING, WAITING).

private static class Process {

int sequenceNumber;

String processClass;

int processArrivalTime;

String currentStatus;

public int deadline;

public int cpuRequest;

public int diskRequest;

public int terminalRequest;

}

// Priority queue for real-time processes

private static PriorityQueue realTimeProcesses = new PriorityQueue(Comparator.comparing(Process::getProcessArrivalTime));

// Queue for interactive processes

private static Queue interactiveProcesses = new LinkedList();

// Queue for disk access requests

private static Queue diskAccessRequests = new LinkedList();

// Queue for terminal access requests

private static Queue terminalAccessRequests = new LinkedList();

// Counter for number of real-time processes that have completed

private static int realTimeProcessesCompleted = 0;

// Counter for number of interactive processes that have completed

private static int interactiveProcessesCompleted = 0;

// Counter for number of disk accesses

private static int diskAccessCount = 0;

// Total time for disk access (including waiting time in the disk queue)

private static int totalDiskAccessTime = 0;

// Time elapsed since start of the first process

private static int totalTimeElapsed = 0;

// CPU utilization (fraction of time the CPU is busy)

private static double cpuUtilization = 0;

// Disk utilization (fraction of time the disk is busy)

private static double diskUtilization = 0;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while (sc.hasNext()) {

String line = sc.nextLine();

String[] tokens = line.split(" ");

if (tokens[0].equals("INTERACTIVE")) {

Process process = new Process();

process.sequenceNumber = Integer.parseInt(tokens[1]);

process.processClass = "INTERACTIVE";

process.processArrivalTime = Integer.parseInt(tokens[2]);

process.currentStatus = "READY";

interactiveProcesses.add(process);

} else if (tokens[0].equals("REAL-TIME")) {

Process process = new Process();

process.sequenceNumber = Integer.parseInt(tokens[1]);

process.processClass = "REAL-TIME";

process.processArrivalTime = Integer.parseInt(tokens[2]);

process.currentStatus = "READY";

realTimeProcesses.add(process);

} else if (tokens[0].equals("DEADLINE")) {

Process process = realTimeProcesses.peek();

process.deadline = Integer.parseInt(tokens[1]);

} else if (tokens[0].equals("CPU")) {

Process process = realTimeProcesses.peek();

process.cpuRequest = Integer.parseInt(tokens[1]);

} else if (tokens[0].equals("DISK")) {

Process process = realTimeProcesses.peek();

process.diskRequest = Integer.parseInt(tokens[1]);

diskAccessRequests.add(process);

} else if (tokens[0].equals("TTY")) {

Process process = realTimeProcesses.peek();

process.terminalRequest = Integer.parseInt(tokens[1]);

terminalAccessRequests.add(process);

}

}

// Simulate process execution

while (!realTimeProcesses.isEmpty() || !interactiveProcesses.isEmpty()) {

// Check for real-time processes

if (!realTimeProcesses.isEmpty()) {

Process process = realTimeProcesses.poll();

process.currentStatus = "RUNNING";

// Print output

System.out.println(process.sequenceNumber + " " + process.processClass + " " + totalTimeElapsed);

// Execute process

int timeTaken = 0;

if (process.cpuRequest > 0) {

timeTaken = process.cpuRequest;

process.cpuRequest = 0;

} else if (process.diskRequest > 0) {

timeTaken = process.diskRequest;

process.diskRequest = 0;

diskAccessCount++;

} else if (process.terminalRequest > 0) {

timeTaken = process.terminalRequest;

process.terminalRequest = 0;

}

// Check if process has completed

if (process.cpuRequest == 0 && process.diskRequest == 0 && process.terminalRequest == 0) {

process.currentStatus = "COMPLETED";

realTimeProcessesCompleted++;

} else {

// Process not completed, add back to priority queue

realTimeProcesses.add(process);

}

// Update total time elapsed

totalTimeElapsed += timeTaken;

}

// Check for interactive processes

if (!interactiveProcesses.isEmpty()) {

Process process = interactiveProcesses.poll();

process.currentStatus = "RUNNING";

// Print output

System.out.println(process.sequenceNumber + " " + process.processClass + " " + totalTimeElapsed);

// Execute process

int timeTaken = 0;

if (process.cpuRequest > 0) {

timeTaken = process.cpuRequest;

process.cpuRequest = 0;

} else if (process.diskRequest > 0) {

timeTaken = process.diskRequest;

process.diskRequest = 0;

diskAccessCount++;

} else if (process.terminalRequest > 0) {

timeTaken = process.terminalRequest;

process.terminalRequest = 0;

}

// Check if process has completed

if (process.cpuRequest == 0 && process.diskRequest == 0 && process.terminalRequest == 0) {

process.currentStatus = "COMPLETED";

interactiveProcessesCompleted++;

} else {

// Process not completed, add back to queue

interactiveProcesses.add(process);

}

// Update total time elapsed

totalTimeElapsed += timeTaken;

}

}

// Calculate average duration of a disk access

double avgDiskAccessTime = 0;

if (diskAccessCount > 0) {

avgDiskAccessTime = (double) totalDiskAccessTime / diskAccessCount;

}

// Calculate CPU and disk utilization

cpuUtilization = (double) totalTimeElapsed / totalTimeElapsed;

diskUtilization = (double) totalDiskAccessTime / totalTimeElapsed;

// Print summary report

System.out.println("Real-time processes completed: " + realTimeProcessesCompleted);

System.out.println("Interactive processes completed: " + interactiveProcessesCompleted);

System.out.println("Number of disk accesses: " + diskAccessCount);

System.out.println("Average duration of a disk access (including waiting time in the disk queue): " + avgDiskAccessTime);

System.out.println("Total time elapsed since start of the first process: " + totalTimeElapsed);

System.out.println("CPU utilization: " + cpuUtilization);

System.out.println("Disk utilization: " + diskUtilization);

}

}

import java. util.*; public class ProcessSchedulingsimulator \{ // Process table with one entry per process containing a process sequence number, // the process class, its process arrival time and its current status (READY, RUNING, WAITING). private static class Process \{ int sequenceNumber; String processClass; int processArrivalTime; String currentStatus; public int deadline; public int cpuRequest; public int diskRequest; public int terminalRequest; \} // Priority queue for real-time processes private static PriorityQueue realTimeProcesses = new PriorityQueue(Comparator. comparing(Process

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions