CS 368 Program 1: List Class

What to Write

First, complete the List class partially defined below by:

Next, add additional fields and methods to allow a client of the List class to iterate through the List, accessing each item in the List, as follows:

Note that neither adding a new item to the end of a list nor printing a list should change the value of the current-object pointer.

To help you understand these methods better, look at the following main function, which first creates a list of strings, then prints each string:

What to Hand In

Put all of your code in a single file named List.java, and hand in your code through student files and do not copy any files other than List.java (for example, do not copy List.class).

Grading Criteria

Your grade will depend on:

The List Class

/*
 *  List class
 *    
 *  A List is an ordered collection of any kind of Object.
 * 
 *  Operations:
 *     AddToEnd    Add a given object to the end of the list.
 *     Print       Print (to standard output) the objects in the list in order,
 *                 enclosed in square brackets, separated by spaces.
 */
class List {
  private static final int INIT_LEN = 10;
  private Object [] items;  // the actual items
  private int numItems;     // the number of items currently in the list
  
  /*
   * constructor: initialize the list to be empty
   */
  public List()
  {
    items = new Object [INIT_LEN];
    numItems = 0;
  }

  /*
   * AddToEnd
   *
   * Given: Object ob
   * Do:    Add ob to the end of the list.
   */
  public void AddToEnd(Object ob)
  {
  }
  
  /*
   * Print
   *
   * Print (to standard output) the objects in the list in order, enclosed in
   * square brackets, separated by spaces.
   */
  public void Print()
  {
  }
}