Implementing a Container Class (sequence)
CS 162 - Spring 2008

Due: 10pm, Monday, March 3
Worth: 100 points

Goals
- to practice class implementations
- to learn more about sequences

Overview
For this lab, you will implement the sequence data type as defined and discussed in chapter 3 of Main's textbook starting on page 142. I've added a toString method. Don't change it.

The ~liffick162/assignfiles/seqA directory contains the class (DoubleArraySeq.java) and the JUnit tests (TestDoubleArraySeq.java) files. There is also a PrintSequence.java printing example you can ignore or play with. You may build another class if you wish to play with the sequence, or you may add some additional tests. The DoubleArraySeq.html file is the JavaDoc documentation that accompanies this assignment.
Focus your effort on implementing the methods of DoubleArraySeq.  

What Your Program Must Do
The JavaDoc format specifications for the class are contained in the DoubleArraySeq.java file as well as in the DoubleArraySeq.html file. You fill in the implementation of the methods. This version implements the sequence using a partially filled array. Pay careful attention to the meaning of addBefore, addAfter, and removeCurrent and what happens when there is and is not a current item.

Looking at the picture above, think about what happens with the various member functions with 2.718 as the current item as shown. What happens if the current item is 3.14 at the beginning? How about if there is no current item? Draw a lot of pictures.

The comments include the class invariant near the top of the implementation file. As you build each method, carefully check that the method is doing what it is supposed to do, changing the instance variables appropriately, and ensuring that the invariant is true when execution leaves the method.

You should practice defensive programming by enforcing the preconditions by throwing IllegalStateException and IllegalArgumentException as noted in the specifications. The other exceptions will occur by themselves and are not tested. The JUnit tests do check for IllegalStateException.

You must use the provided start to the DoubleArraySeq class as found in the DoubleArraySeq.java file.

Your completed class must successfully pass the provided JUnit tests.

How to do it
Understand how each instance variable represents part of the class. Maintain the class invariant.

The book has suggestions for implementing some methods.

Write size, start, advance, isCurrent, and getCurrent. Some of those are trivial. Others need to check their precondition. Then add either addBefore or addAfter.

Realize that System.arraycopy can be very helpful. It can be used with the same array being both the source and destination. See p. 126 of your textbook. Be careful with the parameters. Draw pictures.

Submission
Submit this program as sequence.