CSCI 162 — Lab 3

Due: Sunday October 7, 2018 @ 11:59PM

DoubleArraySequence

Handout Code is available HERE

This includes JUnit tests and empty implementations of DoubleArraySequence.

Goals

Overview

For this assignment you will implement the sequence data type as defined and discussed in Chapter 3 of Main's textbook starting on page 145. I've added a toString method, which you should NOT change.

What Your Program Must Do

The JavaDoc format specifications for the class are contained in the DoubleArraySeq.java file and are also linked on the course page. 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.

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 the method finishes executing.

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.

How to Do It

Understand how each instance variable represents part of the class. Maintain the class invariant.

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. 129. Be careful with the parameters. DRAW PICTURES!

Using JUnit

To run the JUnit tests, you must add the JUnit 4 library to your project. In Eclipse, highlight your project, right click it, and choose Build Path/Add Libraries.... Select JUnit then JUnit 4. Now when you run the JUnit test file, you should run as JUnit Test rather than Java Application. See the JUnit link above for more details.

Submission

Submit DoubleArraySeq.java as the Lab 3: Sequence (Array) lab through Autolab

Grading

100 points total