Assignment #25
Instructions
-
This assignment is the similar to Assignments #19 and #20, except that you must use
class
PriorityQueue<T extends java.lang.Comparable<T>>
as the superclass
for class MyQueue<T extends java.lang.Comparable<T>>
.
-
Write a menu-driven Java program that allows the user to add a name to a line based on priority (a priority queue),
remove and display the next person in line,
display the next person in line,
display the line,
and quit the program.
The program should simulate the scheduling of patients for a hospital operating room.
-
Download these files and store them in the same folder:
starter code: LastnameFirstname25.java
class PriorityQueue: PriorityQueue.java
interface QueueInterface: QueueInterface.java
class Heap: Heap.java
class HeapException: HeapException.java
input file: patients.csv
-
You need to create a Patient class.
-
The Patient class should store the name of the Patient and the priority of the Patient.
-
The name of a Patient can simply be a String.
-
The priority of a Patient is an integer value from 1 to 10, where 1 is a very low priority, and 10 is a very high priority.
-
You need to implement the compareTo() method, so that Patient objects can be sorted in priority order.
Use this code for the first line of your class Patient:
class Patient implements java.lang.Comparable<Patient>
In your class Patient, implement the constructor, toString(), getPriority(), and getName() methods.
In your class Patient, implement the compareTo() method:
public int compareTo(Patient patient2){...}
-
In the
main()
method, take 2 file names as the commandline input.
The first file args[0]
is the input file.
The second file args[1]
is the output file.
-
The input file is a text file with a list of patients with names and priority numbers. For example, see patients.csv
-
From the
main()
method, call a method that reads the data in the file,
and store each each name in a MyQueue
object which is a subclass of class
PriorityQueue<T extends java.lang.Comparable<T>>
by using my QueueInterface.java and PriorityQueue.java
and Heap.java files.
-
The second method called in the
main()
method should display a JOptionPane.showOptionDialog()
menu.
The menu has the following choices: "Offer Person", "Poll Person", "Peek Person", "Display List", and "Exit Program".
Here is example code that shows you how to use a JOptionPane.showOptionDialog()
menu:
MenuExample.java.
-
The third method called in the
main()
method should write the Patient's names and priorities
in the queue to the output file.
The output file should have the same format as the input file.
In other words, the output file should have "priority,name" as the 1st line of the file.
The 2nd, 3rd, 4th, etc. lines of the file should have the priority,name for the specific Patients
who are still stored in the priority queue.
The 2nd line of the output file would be the 1st Patient.
The 3rd line of the output file would be the 2nd Patient.
The 4th line of the output file would be the 3rd Patient. Etc.
The Patients should be ordered by the most critical to the least critical.
See the example output file below.
-
Below your
LastnameFirstname20
class, create a second class in your LastnameFirstname25.java
file,
which is the class MyQueue
which is a subclass of class PriorityQueue<T extends java.lang.Comparable<T>>
.
-
The constructor for class
MyQueue<T extends java.lang.Comparable<T>>
is not needed.
-
The
toString()
method should use the class Heap's toString()
method.
Class PriorityQueue stores a data field called "heap" that you can use in this method.
-
Write your original comments every 3-5 lines of code.
-
WARNING: In the edit method, do NOT copy my code or my comments.
Use my code as a guide to write your own code.
-
Don't forget to add "JavaDoc" style comments above each method.
See ICS 211 Java Coding Standard (Comments: Methods) for details.
Output
-
Here is example output for commandline arguments:
patients.csv patients2.csv
Click "Offer Person" Button:
Click "Poll Person" Button:
Click "Peek Person" Button:
Click "Display Queue" Button:
Click "Exit Program" Button: