Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*********here is extra mention*************** Here is job.java: public class Job { private int jobNumber; private int requiredExecutionTime; private int givenExecutionTime; private int entryTime; private int

image text in transcribedimage text in transcribed

image text in transcribed

*********here is extra mention***************

image text in transcribed

Here is job.java:

public class Job {

private int jobNumber; private int requiredExecutionTime; private int givenExecutionTime; private int entryTime; private int priority; public Job(int aJobNumber, int aRequiredExecutionTime, int aPriority) { jobNumber = aJobNumber; requiredExecutionTime = aRequiredExecutionTime; priority = aPriority; givenExecutionTime = 0; entryTime = 0; } public int getJobNumber() { return jobNumber; } public void setJobNumber(int jobNumber) { this.jobNumber = jobNumber; }

public int getEntryTime() { return entryTime; } public void setEntryTime(int entryTime) { this.entryTime = entryTime; } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } public int getRequiredExecutionTime() { return requiredExecutionTime; } public void setRequiredExecutionTime(int requiredExecutionTime) { this.requiredExecutionTime = requiredExecutionTime; } public int getGivenExecutionTime() { return givenExecutionTime; } public void setGivenExecutionTime(int givenExecutionTime) { this.givenExecutionTime = givenExecutionTime; } public String toString() { return jobNumber +""; } }

Here is OperatingSystemTest.java:

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

public class OperatingSystemTest {

@Test public void noJobs() { ArrayList testOne = new ArrayList(); ArrayList results = OperatingSystem.JobScheduler(testOne); assertEquals("When checking the number of elements returned, we",0,results.size()); }

@Test public void oneJob() { Job aJob = new Job(1,5,1); ArrayList testOne = new ArrayList(); testOne.add(aJob); ArrayList results = OperatingSystem.JobScheduler(testOne); assertEquals("When checking the number of elements returned, we",1,results.size()); assertEquals("At CPU time 5 Job Number 1 finished processing",results.get(0)); } @Test public void twoJobsNoActiveJobStack() { Job aJob = new Job(1,7,1); Job jobTwo = new Job(2,3,4); ArrayList testTwo = new ArrayList(); testTwo.add(aJob);testTwo.add(jobTwo); ArrayList results = OperatingSystem.JobScheduler(testTwo); assertEquals("When checking the number of elements returned, we",2,results.size()); assertEquals("At CPU time 7 Job Number 1 finished processing",results.get(0)); assertEquals("At CPU time 10 Job Number 2 finished processing",results.get(1)); } @Test public void twoJobsWithActiveJobStack() { Job aJob = new Job(1,6,3); Job jobTwo = new Job(2,7,2); ArrayList testThree = new ArrayList(); testThree.add(aJob);testThree.add(jobTwo); ArrayList results = OperatingSystem.JobScheduler(testThree); assertEquals("When checking the number of elements returned, we",2,results.size()); assertEquals("At CPU time 8 Job Number 2 finished processing",results.get(0)); assertEquals("At CPU time 13 Job Number 1 finished processing",results.get(1)); } @Test public void fourJobsNoActiveJobStack() { Job aJob = new Job(1,6,1); Job jobTwo = new Job(2,7,2); Job jobThree = new Job(3,2,3); Job jobFour = new Job(4,11,4); ArrayList testFour = new ArrayList(); testFour.add(aJob);testFour.add(jobTwo);testFour.add(jobThree);testFour.add(jobFour); ArrayList results = OperatingSystem.JobScheduler(testFour); assertEquals("When checking the number of elements returned, we",4,results.size()); assertEquals("At CPU time 6 Job Number 1 finished processing",results.get(0)); assertEquals("At CPU time 13 Job Number 2 finished processing",results.get(1)); assertEquals("At CPU time 15 Job Number 3 finished processing",results.get(2)); assertEquals("At CPU time 26 Job Number 4 finished processing",results.get(3)); } @Test public void fourJobsWithActiveJobStack() { Job aJob = new Job(1,6,6); Job jobTwo = new Job(2,7,2); Job jobThree = new Job(3,2,1); Job jobFour = new Job(4,11,4); ArrayList testFive = new ArrayList(); testFive.add(aJob);testFive.add(jobTwo);testFive.add(jobThree);testFive.add(jobFour); ArrayList results = OperatingSystem.JobScheduler(testFive); assertEquals("When checking the number of elements returned, we",4,results.size()); assertEquals("At CPU time 4 Job Number 3 finished processing",results.get(0)); assertEquals("At CPU time 10 Job Number 2 finished processing",results.get(1)); assertEquals("At CPU time 21 Job Number 4 finished processing",results.get(2)); assertEquals("At CPU time 26 Job Number 1 finished processing",results.get(3)); } }

***************I added Stack.java and Queue.java that you might need**********************

Here is Stack.java

public class Stack {

private E[] stack; private int size; @SuppressWarnings("unchecked") public Stack() { stack = (E[]) new Object[500]; size = -1; } public int size() { return size + 1; } public boolean isEmpty() { if(size == -1) { return true; } else { return false; } } public E peek() { if(isEmpty() == true) { return null; } else { return stack[size]; } } public E pop() { if(isEmpty() == true) { return null; } else { E toReturn = stack[size]; stack[size] = null; size--; return toReturn; } } public void push(E anElement) { if(size() == stack.length) { throw new IllegalStateException(); } else { size++; stack[size] = anElement; } } }

Here is Queue.java

//First In First Out FIFO public class Queue {

private SinglyLinkedList linkedList; public Queue() { linkedList = new SinglyLinkedList(); } public int size() { return linkedList.getSize(); } public boolean isEmpty() { return linkedList.isEmpty(); } public E first() { if(isEmpty() == true) { return null; } else { return linkedList.getFirst(); } } public E dequeue() { if(isEmpty() == true) { return null; } else { return linkedList.removeFirst(); } } public void enqueue(E anElement) { linkedList.addLast(anElement); } @SuppressWarnings("hiding") public class SinglyLinkedList { //Instance Variables private Node head; private Node tail; private int size; //Default Constructor public SinglyLinkedList() { size = 0; } //Getter methods public int getSize() { return size; } public boolean isEmpty() { boolean toReturn = false; if(size == 0) { toReturn = true; } return toReturn; } public E getFirst() { if(isEmpty() == true) { return null; } else { return head.getElement(); } } public E getLast() { if(isEmpty() == true) { return null; } else { return tail.getElement(); } } //Setter methods public void addLast(E anElement) { //Create a new node with the given element. Because this is the last node in the linked list, we set the value of the new nodes next node //to null, as there is no next node Node newNode = new Node(anElement,null); //If the linked list is empty we make the new node the head node because it will be both the head and the tail node. if(isEmpty() == true) { head = newNode; } else { //If the linked list has nodes in it already, we link the new node to the current tail of our linked list tail.setNextNode(newNode); } //We update the tail and size instance variables tail = newNode; size++; }

public E removeFirst() { if(isEmpty() == true) { return null; } else { E toReturn = head.getElement(); head = head.getNextNode(); size--; if(size == 0) { tail = head; } return toReturn; } } }

public class Node { //Instance Variables private G element; private Node next; //Parameterized Constructor public Node(G anElement, Node nextNode) { element = anElement; next = nextNode; } //Getters and setters public G getElement() { return element; } public void setElement(G anElement) { element = anElement; } public Node getNextNode(){ return next; } public void setNextNode(Node nextNode) { next = nextNode; } public String toString() { return element.toString(); } } }

rite a program to simulate job scheduling in an operating system. In this simulation, we will have jobs which need to be run on a processor to complete. Each job will take a varying number of clock cycles to execute. When the required number of clock cycles has passed, the job is removed from the processor and is considered to be completed. At the start of each clock cycle, the processor checks if it is currently running a job. If it is, it spends another cycle working on that job. If the processor is not running a job, it gets a job from the input queue and begins running it. The input queue contains all jobs which need to be executed. Jobs have priority as well. A job's priority is represented by an integer value between 1 and 4, where 1 is the highest priority and 4 is the lowest priority. At the start of each clock cycle, the processor checks the first job in the input queue. If that job has a lower priority that the job currently being run by the processor (or the processor is not currently running a job), then the system behaves as described in the previous paragraph. But if the first job in the input queue has a higher priority than job the processor is currently running, then the job from the queue is run by the processor. The job which was being run by the processor is pushed onto the active job stack. Job's placed on the active job stack keep all the work that had beern completed while being run by the processor. (So if a job needs to run for 5 clock cycles to complete, and had run for 2 clock cycles before being placed on the active job stack, it would only need to be run for 3 more clock cycles before being completed) At the end of each clock cycle, we determine if the current job has been run for the necessary number of clock cycles. If it has, the job is completed and we remove it from the processor Once removed, we pop the top element off the active job stack and place it back on the processor. Once placed the clock cycle ends and the process starts over from the start. The simulation is considered complete when the input queue is empty, the active job stack is empty, and there is no job being run by the processor input Input Queue Processor Exit Active Job Stack

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_2

Step: 3

blur-text-image_3

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

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

8. Identify the meeting with the goddess in The Elephant Man.

Answered: 1 week ago

Question

4. How is culture a contested site?

Answered: 1 week ago