Assignment #19

Instructions

  1. Write a menu-driven Java program that allows the user to add a name to a line (queue), remove and display the next person in line, display the next person in line, display the line, and quit the program.
    1. Download these files and store them in the same folder:
      starter code: LastNameFirstName19.java
      class ArrayQueue: ArrayQueue.java
      interface QueueInterface: QueueInterface.java
      input file: input19.txt
    2. 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.
    3. The input file is a text file with a list of names. For example, see input19.txt
    4. 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 ArrayQueue by using my QueueInterface.java and ArrayQueue.java files.
    5. 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.
    6. The third method called in the main() method should write the names in the queue to the output file.
    7. Use the JOptionPane.showMessageDialog() method for your output.
    8. Use the JOptionPane.showInputDialog() method to ask the user for input.
  2. Below your LastnameFirstname19 class, create a second class in your LastnameFirstname19.java file, which is the class MyQueue which is a subclass of class ArrayQueue.
    1. The constructor for class MyQueue have an int parameter that is used to initialize the superclass ArrayQueue<T>. Use the method call:
      super(max);
      where "max" is the int parameter, so that the ArrayQueue's constructor can initialize the maxSize. You will only have 1 line of code in the MyQueue constructor.
    2. The toString() method should return a String that displays each name on a different line. See the example output below. Note that your toString() method must loop through the array of superclass ArrayQueue<T>, as the main point of this assignment is to learn more about how an array-based queue works. In other words, you should not use the poll(), peek(), or offer() methods in the toString() method. Instead, you should loop from the frontIndex to the endIndex of the array in the toString() method. You need to use modulus (%) to wraparound the circular array. You should only use the poll(), peek(), or offer() methods in the class LastNameFirstName19.java.
  3. Write your original comments every 3-5 lines of code.
  4. WARNING: In the edit method, do NOT copy my code or my comments. Use my code as a guide to write your own code.
  5. 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: input19.txt output19.txt
    Click "Offer Person" Button:
    Queue (line) of People
    Enter person's name
    Click "Poll Person" Button:
    Queue (line) of People
    Fred is next in line
    Click "Peek Person" Button:
    Queue (line) of People
    Stella is in front of the line
    Click "Display Queue" Button:
    Queue (line) of People
    Display Line
    Click "Exit Program" Button:
    Queue (line) of People

Click to validate the HTML code

Click to validate the CSS code