Link to driver: https://cse.sc.edu/~shephejj/csce146/Labs/ProcessQueueSimulatorF
ID: 3888923 • Letter: L
Question
Link to driver:
https://cse.sc.edu/~shephejj/csce146/Labs/ProcessQueueSimulatorFiles/ProcessSchedulerSimulator.java
Objective: Write a program which simulates first come first serve scheduling using a queue. Download the driver and include it in your project. Create a class Process with the following: Attributes o Name: the name given to the process o Completion time: a positive decimal value that indicates how long the process has until it is finished Constructors o Default o Parameterized Accessors and Mutators for all attributes. MAKE SURE TO CHECK FOR VALID VALUES Other methods: o toString: Takes in nothing via a parameter and returns a string showing the process's 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 following o Attributes Data: the data that's held in the node of a generic type Link: a ListNode that points to the next element o Constructors: . Default Parameterized Attributes o Head: A ListNode that points to the first element of the queue oTail: AListNode that points to the last element of the queue Other Methods oEnqueue: This method returns nothing and t akes in some generic data that is added to the end of the queue. o Dequeue: This method removes and returns the first element's data of the queue as long as the head is not null o Peek: Returns the first element's data, but doesn't remove the element. o Print: Prints out the entire queueExplanation / Answer
Create the following three classes and also add the driver class in a single java project (with in the same package) and run the driver as an java application
Code for Process Class
public class Process {
String name;
double completionTime;
public Process(String name, double completionTime) {
this.name = name;
this.completionTime = completionTime;
}
public Process()
{
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getCompletionTime() {
return completionTime;
}
public void setCompletionTime(double completionTime) {
if(completionTime > 0)
this.completionTime = completionTime;
else
System.out.println("Completion time should be non negative");
}
public String toString()
{
return (this.name + this.completionTime);
}
}
Code for LinkedListQueue class
public class LinkedListQueue<Type> {
class ListNode<Type>
{
public Type data;
private ListNode<Type> next;
public ListNode(Type data) {
this.data = data;
this.next = null;
}
public ListNode()
{
}
}
ListNode<Type> head, tail;
public void enqueue(Type data) {
ListNode<Type> node = new ListNode<Type>(data);
tail.next = node;
tail = node;
}
public ListNode<Type> dequeue()
{
if(head != null)
{
head = head.next;
return head;
}
else
return null;
}
public Type peek()
{
if(head != null)
{
return head.data;
}
else
return null;
}
public void printList(ListNode<Type> node) {
if(node != null)
{
System.out.print(node.data + " ");
printList(head.next);
}
}
public void remove(Type data)
{
ListNode<Type> curr = head;
ListNode<Type> prev = null;
while(curr != null)
{
if(curr.data == data)
{
if(prev != null)
prev.next = curr.next;
else
{
head = head.next;
break;
}
}
prev = curr;
curr = curr.next;
}
}
public void print()
{
System.out.println("hererere");
printList(head);
}
}
Code for Process Scheduler Class
public class ProcessScheduler {
LinkedListQueue<Process> processes;
Process currentProcess;
public Process getCurrentProcess() {
return currentProcess;
}
public void setCurrentProcess(Process currentProcess) {
this.currentProcess = currentProcess;
}
public void addProcess(Process p)
{
if(getCurrentProcess() == null)
{
setCurrentProcess(p);
}
else
{
if(processes != null)
processes.enqueue(p);
}
}
public void runNextProcess()
{
if(processes != null )
{
LinkedListQueue<Process>.ListNode<Process> p = processes.dequeue();
setCurrentProcess(p.data);
}
}
public void cancelCurrentProcess()
{
Process cp = getCurrentProcess();
runNextProcess();
if(processes!= null)
processes.remove(cp);
}
public void printProcessQueue()
{
if(processes != null)
processes.print();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.