CMPU 102 - Assignment 2
List ADT
Assigned: Fri, Feb   8
Due: Fri, Feb 15

IList implementation of List ADT

In this assignment you will:
  1. use the IList class hierarchy to implement ADT List operations,
  2. use NetBeans to modify an existing project, and
  3. use the submit102 script from the Linux prompt to hand in your project.

Summary:
You will implement a list ADT for lists of integers. The data structure behind the wall will be the IList class hierarchy we studied at the end of Fall 2007 in CS 101. The ADT you will implement is from Ch. 4 of the text, IntegerListInterface, on pp. 209-210. Since you will use an IList to implement your ADT, the class that will implement the IntegerListInterface will be named IntegerListIListBased. 

Download the starter project

  1. Click here to download the starter project: Assign2.zip
  2. Save it in your cs102 directory.
  3. Unzip the file.
  4. You should be able to Open this as an existing project in NetBeans (described next)

Launch NetBeans and Open Project

  1. From NetBeans, go to the File menu and select "Open Project" -- or click on the third button from the left on the button bar.
  2. Navigate to your cs102 folder and select the folder named "Assign2" 
  3. The "Open Project Folder" button should be enabled. Click it to open the starter project.
  4. There are many source files in this project, but the only one you need to modify is IntegerListIListBased.java.

The IntegerListIListBased Class

In this class we've left the stubs (headers and empty bodies) for all the methods in the IntegerListInterface that must be implemented. You are permitted to use only the methods provided by the IList class hierarchy (data structure) to implement the ADT methods. In addition, you must override toString().

What follows is the contents of file IntegerListInterface.java--the Java interface for the ADT list you will be implementing.

// ********************************************************
// Interface IntegerListInterface for the ADT list.
// *********************************************************
public interface IntegerListInterface {
   public boolean isEmpty();
   // Determines whether a list is empty.
   // Precondition: None.
   // Postcondition: Returns true if the list is empty,
   // otherwise returns false.
   // Throws: None.

   public int size();
   // Determines the length of a list.
   // Precondition: None.
   // Postcondition: Returns the number of items that are
   // currently in the list.
   // Throws: None.

   public void removeAll();
   // Deletes all the items from the list.
   // Precondition: None.
   // Postcondition: The list is empty.
   // Throws: None.
   public void add(int index, int item)
            throws ListIndexOutOfBoundsException,
                   ListException;
   // Adds an item to the list at position index.
   // Precondition: index indicates the position at which 
   // the item should be inserted in the list.
   // Postcondition: If insertion is successful, item is
   // at position index in the list, and other items are
   // renumbered accordingly.
   // Throws: ListIndexOutOfBoundsException if index < 1 or
   // index > size()+1.
   // Throws: ListException if item cannot be placed on
   // the list.

   public int get(int index) throws
         ListIndexOutOfBoundsException;
   // Retrieves a list item by position.
   // Precondition: index is the number of the item to be
   // retrieved.
   // Postcondition: If 1 <= index <= size(), the item at
   // position index in the list is returned.
   // Throws: ListIndexOutOfBoundsException if index < 1 or
   // index > size().

   public void remove(int index)
               throws ListIndexOutOfBoundsException;
   // Deletes an item from the list at a given position.
   // Precondition: index indicates where the deletion
   // should occur.
   // Postcondition: If 1 <= index <= size(), the item at
   // position index in the list is deleted, and other items
   // are renumbered accordingly.
   // Throws: ListIndexOutOfBoundsException if index < 1 or
   // index > size().

} // end IntegerListInterface

Sample Output

When your IntegerListIListBased class is fully implemented, running the code in Main will produce the following output:

init:
deps-jar:
Compiling 1 source file to /Users/mlsmith/Desktop/Assign2/build/classes
compile:
run:
Create and initialize new IList-based integer list...

list of size 10 = (3, ((5, ((7, ((9, ((11, ((13, ((15, ((17, ((19, ((21, (()))))))))))

Remove elements at position 10, 5, and 1 from list...

list of size 7 = (5, ((7, ((9, ((13, ((15, ((17, ((19, (())))))))

Get elements at position 1 and 7...
   element at position 1 = 5
   element at position 7 = 19

List empty? (should be false): false

Remove all the remaining elements from list...

List empty? (should be true): true
BUILD SUCCESSFUL (total time: 0 seconds)

Once you've run and verified that your IntegerListIListBased class is implemented properly, you are ready to submit your project.


Submitting your solution

From a terminal window, type the following commands:
cd
cd cs102 
submit102 Assign2