Question
Objective: IN JAVA Write a program which simulates first come first serve scheduling using a queue. Download the driver( DRIVER AT END OF DOC) and
Objective:
IN JAVA
Write a program which simulates first come first serve scheduling using a queue. Download the driver(DRIVER AT END OF DOC) and include it in your project.
Create a class Process with the following:
Attributes
Name: the name given to the process
Completion time: a positive decimal value that indicates how long the process has until it is finished
Constructors
Default
Parameterized
Accessors and Mutators for all attributes. MAKE SURE TO CHECK FOR VALID VALUES!
Other methods:
toString: Takes in nothing via a parameter and returns a string showing the processs name and completion time.
Create a class LinkedListQueue with the following:
Assume this is will have a generic type
An internal class ListNode with the followingAttributes:
Data: the data thats held in the node of a generic type
Link: a ListNode that points to the next element
Constructors:
Default
Parameterized
Attributes
Head: A ListNode that points to the first element of the queue
Tail: A ListNode that points to the last element of the queue
Other Methods
Enqueue: This method returns nothing and takes in some generic data that is added to the end of the queue.
Dequeue: This method removes and returns the first elements data of the queue as long as the head is not null.
Peek: Returns the first elements data, but doesnt remove the element.
Print: Prints out the entire queue.
Create a class called ProcessScheduler with the following:
Attributes:
Processes: This is a linked list queue of processes. Hence forth known as the process queue.
Current Process: This is the currently running process of type Process.
Methods:
getCurrentProcess: This method takes no parameters and returns the currently running process. Note that this is not the first element of the process queue.
addProcess: Taking in a process via a parameter it either sets the current process if the current process is null or it adds it to the process queue. Also it doesnt return any values.
runNextProcess: This method dequeues from the process queue and sets that to the current process.
cancelCurrentProcess: The current process is cancelled and is replaced by the first element on the process queue. Make sure that the process is also removed from the process queue after the current process has been set. Neither parameters nor return values are expected for this method.
printProcessQueue: This method should print all of the elements from the process queue.
Extra Notes:
Make sure to call methods youve already defined to keep this as simple as possible. For instance the ProcessScheduler class shouldnt be all that long as most of the functionality has already been defined in the LinkedListQueue.
DRIVER:
import java.util.*; public class ProcessSchedulerSimulator { public static final int MAX_SIM_TIME = 50;//Max cycle times public static final double MAX_PROC_TIME = 15.0; public static final int RAND_ADD_VAL = 3;//A value that adds a new process only when it's a multiple. public static final int RAND_CANCEL_VAL = 23;//A value that ends the current process only it's a multiple. public static Random rng = new Random(10);//Random number generator. Add a number into its parameter to fix its seed value public static void main(String[] args) { //Creating process scheduler ProcessScheduler scheduler = new ProcessScheduler(); int currProcCount = 0; Process currProcess; printHeader("Welcome to the process scheduler simulator"); System.out.println(" "); for(int i=0;i0.0) { printAction("Current Process "+currProcess.toString()); currProcess.setCompletionTime(currProcess.getCompletionTime()-1.0); printAction("Updating Completion Time "+currProcess.toString()); } else { printAction("Current Process Complete"); scheduler.runNextProcess(); currProcess = scheduler.getCurrentProcess(); if(currProcess!=null) { printAction("New current process "+currProcess.toString()); } else { printAction("No current process"); } } //Check status of the process queue printAction("Current Process Queue"); scheduler.printProcessQueue(); } } public static void addRandomProcess(ProcessScheduler scheduler, int count) { String name = "Process"+(count); double randTime = rng.nextDouble()*MAX_PROC_TIME; Process p = new Process(name,randTime); printAction("Adding a new Process " + p.toString()); scheduler.addProcess(p); } public static void printHeader(String data) { System.out.println("--------------------------- "+data+" ---------------------------"); } public static void printAction(String data) { System.out.println("***"+data+"***"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started