Assignment #25

Instructions

  1. 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>>.
  2. 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.
    1. 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
    2. You need to create a Patient class.
      1. The Patient class should store the name of the Patient and the priority of the Patient.
      2. The name of a Patient can simply be a String.
      3. 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.
      4. 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){...}
    3. 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.
    4. The input file is a text file with a list of patients with names and priority numbers. For example, see patients.csv
    5. 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.
    6. 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.
    7. 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.
  3. 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>> .
    1. The constructor for class MyQueue<T extends java.lang.Comparable<T>> is not needed.
    2. 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.
  4. Write your original comments every 3-5 lines of code.
  5. WARNING: In the edit method, do NOT copy my code or my comments. Use my code as a guide to write your own code.
  6. Don't forget to add "JavaDoc" style comments above each method. See ICS 211 Java Coding Standard (Comments: Methods) for details.

Output

  1. Here is example output for commandline arguments: patients.csv patients2.csv
    Click "Offer Person" Button:
    Scheduling of Patients for a Hospital Operating Room
    Enter patients's name
    Enter patients's priority
    Error message
    Enter patients's priority
    Error message
    Enter patients's priority
    Error message
    Enter patients's priority
    Click "Poll Person" Button:
    Scheduling of Patients for a Hospital Operating Room
    Betty is next in line
    Click "Peek Person" Button:
    Scheduling of Patients for a Hospital Operating Room
    BEVIS is in front of the line
    Click "Display Queue" Button:
    Scheduling of Patients for a Hospital Operating Room
    Display Line
    Click "Exit Program" Button:
    Scheduling of Patients for a Hospital Operating Room