Question: Write a program which uses an ArrayList to create a priority queue (PQ) of type PriorityQueue. The data records to be dealt with are simulated

Write a program which uses an ArrayList to create a priority queue (PQ) of type PriorityQueue. The data records to be dealt with are simulated process identifiers pids which might be managed by the operating system of a computer.

You need to write a method to process records. For our assignment, a process has at least a pid, a priority, and an increment all of which are integer values. It also has a name, which is a String. All the values, pid, priority, increment and name should be stored as a single object in the PQ. This means you will need to store these values inside your class and instantiate the object. Then store those objects in the PQ, but prioritize the process on its priority value.

The pid is the unique identifier given to the process by the operating system when the process is started. The priority is the current priority of the process and is the value on which you are to sort the PQ.

The increment is a value that can be given to a process; this would be the increment to the processs priority that would be applied by the operating system at the next interval.

In some operating systems, a process that was hogging memory or CPU might

have its priority either raised (to help get the process out of the system and free

up some resources) or lowered (to allow the large number of other processes to

get through the system), and this increment value could be used to change the

priority of a process.

(In a real operating system, the data record that represented the process

would have a number of other attributes, such as memory usage, files open,

parent process, the login id of the user who fired up the process, and such. To

see some of this in action, just log in to any Unix/linux system and run

top to display some of the information. On a Windows machine, the task manager

will display some of this information.)

This assignment will require you to write an insertion sort. Using a PQ (backed by an ArrayList) with an insertion sort to implement a priority queue is only one way to do a priority queue. There are probably better ways, but this is an easy way to learn without making for a huge project.

The main program will do some of the typical things that we have been doing in previous assignments, such as opening/reading files and processing the data in some way, using a class and instantiating and object of your own class, calling methods, etc.

You will need to read in process records (from a file) and insert them into a priority queue (PQ) in descending sorted order based on the value of key, which is also the priority. After you finish, you will need to read in another file to delete some processes from the queue. I will publish some example files later. Create your own at first. Call the files assn4add.txt and assn4del.txt for the items to be added and deleted.

When you add or remove a priority, you will need to keep the list sorted.

NOTE: A PQ requires a compareTo() method. You will need to create your own compareTo method for this project to work correctly. This may take a little while to figure out, so do not wait until too late to start

assn4add.txt text file: https://drive.google.com/open?id=1LusdYPoMyX9jzimgSgLo_PBFNIbZvydsUrSY0HVTYQs

assn4del.txt text file: https://drive.google.com/open?id=1YTLyp2qJmQips4Lx6uhLkXbVUB1qW2jeUQZGBvkVTqk

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!