Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10pts] Suppose you were working on a class Date that represents a date, obviously, and would provide basic functionality for reading dates in various formats, writing dates in various formats, and doing other date-related tasks. You will certainly want an array of the names of the months for both reaing and writing. It gives you an easy way to convert month "1" to month "January". Which of the following is the most appropriate declaration for the field. Explain your answer thorougly!
    1. public String[] mnames = {"January", "February", "March", "April", "May", "June", 
                                 "July", "August", "Septemnber", "October", "November", "December"};
    2. public static String[] mnames = {"January", "February", "March", "April", "May", "June",
                                        "July", "August", "Septemnber", "October", "November", "December"};
    3. public static final String[] mnames = {"January", "February", "March", "April", "May", "June", 
                                              "July", "August", "Septemnber", "October", "November", "December"};
    4. private static String[] mnames = {"January", "February", "March", "April", "May", "June", 
                                         "July", "August", "Septemnber", "October", "November", "December"};
    5. private static String[] mnames = {"January", "February", "March", "April", "May", "June",
                                         "July", "August", "Septemnber", "October", "November", "December"};
    6. private static final String[] mnames = {"January", "February", "March", "April", "May", "June", 
                                               "July", "August", "Septemnber", "October", "November", "December"};
  2. [90pts] A "queue" is an object that stores data. It has a very simple interface that mimics the behaviour of waiting in a line (or a "queue" as the British say). Specifically, its interface is: empty which tells you whether the queue is empty, enqueue which adds data to the "back" of the queue, and dequeue which removes a piece of data from the front of the queue. Your job is to define a class Queue for storing queues of strings. Here is the interface it must support:
    Interface for Queue class Node for you to use
      /**
       * adds s to the back of the queue
       */
      public void enqueue(String s) { ... }
    
      /**
       * removes and returns string from the front of the queue
       */
      public String dequeue() { ... }
    
      /**
       * returns true if the queue is empty
       */
      public boolean empty() { ... }
    You'll use a linked list of course. To be helpful, I've created a Node class for you:
    public class Node
    {
      public String data;
      public Node next;
      public Node(String d, Node n)
      { 
        data = d; 
        next = n;
      }
    }
    We'll let the data be public here so that the data and next fields are accessible from within the class Queue.

    Note: Since you'll want to add to the back of the list, you should really keep a pointer to the last node of the list as well as the first node (see diagram to the right). This makes adding to the back of the list easy.

    The file HW07.java should work with your Queue implementation. If you've done it right, then you should be able to run HW07 like this:
    ~/$ java HW07
    this is the end done
    this
    is
    the
    end

Turn in this sheet, along with a printout of yrou Queue.java source code, and a screen capture showing HW07 running on the above input.