Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OBJECTIVE IN JAVA. PLEASE FOLLOW DIRECTIONS ACCORDINGLY AND SHOW OUTPUT. Create

ID: 3806572 • Letter: O

Question

OBJECTIVE IN JAVA. PLEASE FOLLOW DIRECTIONS ACCORDINGLY AND SHOW OUTPUT.

Create a couple of classes that will simulate a process heap. Download the driver and follow the following instructions!

//DRIVER

Create a class called Process

- Instance variables:

- Priority: which is an integer value that corresponds to where it will be in the heap. Needs to be greater than 0.

- Time: A double value that corresponds to how long the process will take to run. Needs to be greater than 0.

- Name: A string value that is the name of the process

- Constructors: Default and Parameterized

- Accessors and mutators for each instance variable

- Make sure to check for valid values.

- Other methods:

- toString: a method that prints out the name, priority, and time

Create another class called ProcessHeap

- Instance variables:

- Heap: an array of type Process which represents the heap

- Size: the number of elements in the heap

- Constructors: Default and parameterized

- Other methods:

- insert: this method which returns nothing adds a new element to the heap. It always adds the next element as the next element in breadth order and then bubbles it up based on the priority of the Process.

- peek: this returns the head of the heap

- remove: This returns the root of the heap and then removes it from the heap. It must then move the last element in the heap (via breadth order) to the root and bubble that value down until it’s in the correct location.

- printHeap: Prints the heap out in breadth order

- isEmpty: returns a true or false value for whether or not the queue is empty

- heapSort: Prints out the heap in sorted order. The idea is to remove an element print that element and then repeat that until there are no more elements.

Explanation / Answer

public class ProcessSimulator { public static void main(String[]args) { final int HEAP_SIZE = 100; ProcessHeap heap = new ProcessHeap(HEAP_SIZE); //Make initial heap heap.insert(new Process("a",10,50)); heap.insert(new Process("b",5,20)); heap.insert(new Process("c",20,18)); heap.insert(new Process("d",18,29)); heap.insert(new Process("e",33,23)); heap.insert(new Process("f",1,15)); heap.insert(new Process("g",16,5)); System.out.println("The current heap is:"); heap.printHeap(); ProcessHeap.heapSort(heap); System.out.println("Starting simulation"); //Simulation final int SIM_TIME = 250; Process currProcess = null; double currProcessTime = 0.0; for(int i=0;i0.0) { currProcessTime--; } else { System.out.println("Process: "+currProcess.toString()+" has ended"); currProcess = null; } //New process added if(i%50 == 0 && i!=0) { Process randomProcess = new Process("Random Process "+i,i/5,i/5); heap.insert(randomProcess); System.out.println("Random process added! "+randomProcess.toString()); } } System.out.println("Simulation time has expired"); } }