Lab: Sequence Implementation on Stack
Important: Remember that you are now required to work on the lab with your partner. Although you and your partner can choose to both follow the Setup instructions below, the recommended way to work on the lab is for one student to download and set up the lab's Eclipse project and then share it with the partner through the team's Subversion repository (the way you learned in the previous lab). This way you can work on the lab together on one computer and then share the resulting work through the repository.
Objective
In this lab you will practice implementing and testing a kernel
component, Sequence3 implemented on Stack .
Setup
Follow these steps to set up a project for this lab. For this lab,
instead of creating a new project, you will import a project already
set-up for this lab. First you need to download the project,
SequenceOnStack.zip, to your computer. Click on this download
link and save the file somewhere on your hard
drive where you can easily find it. Make sure that you do not expand
this archive. If your browser automatically expands downloaded zip
archives, that's OK too. Just pay attention to the special instructions
in the following few steps. You may want to make a note of where you
saved it.
Import your new project by following these steps:
- From the File menu select Import....
- In the new window, expand General and select Existing Projects into Workspace. Click Next.
- Click on the radio button next to Select archive file and then click the Browse... button. (If the archive was expanded when you downloaded the file to your own computer, click on Select root directory... instead.)
- In the file selection window, find the
SequenceOnStack.zipfile and select it. (If your browser expanded the archive, find theSequenceOnStackdirectory instead.) Click OK. - Click Finish.
Method
- Take a look at the
srcandtestfolders in your new project. Open theSequence3.javafile in thesrcfolder and explore it. In particular, take a look at the private members (the representation) at the top of the class and the correspondence in the Javadoc comment for the class. The correspondence clause is a mathematical statement that describes how a client should interpret the variables in the data representation (denoted by$thisfollowed by a dot and the name of the instance variable) as an abstract value of aSequencevariable (writtenthis). (Note that the notation$thisnever appears in Java code, but only in Javadoc comments like this that describe aspects of the data representation!) - Paste the code you wrote for the homework into the body of the
private method
setLengthOfLeftStack, and complete the body of the kernel methods (add,remove, andlength) inSequence3in thesrcfolder. - Paste the test cases you designed for the homework at the end of the
SequenceTestclass in thetestfolder. - Run
Sequence3Testin thetestfolder to test your implementation ofSequence3. Fix any bugs that you discover and/or add extra test cases, if you realize that you are missing some important cases.
Additional Activities
-
Copy and paste the following piece of code at the end of
Sequence3(after theiteratormethod and before the class closing '}')./* * Other methods (overridden for performance reasons) --------------------- */ @Override public final void flip() { // TODO - fill in body }Provide a non-layered implementation of the secondary method
flipdefined inSequence. Note that there is a simple, clever solution to this that does not involve iteration or recursion. -
Add appropriate test cases for the
flipmethod toSequenceTestand test your implementation. -
Copy and paste the following piece of code at the end of
Sequence3(after theiteratormethod and before the class closing '}')./* * Other methods (overridden for performance reasons) --------------------- */ @Override public final T entry(int pos) { assert 0 <= pos : "Violation of: 0 <= pos"; assert pos < this.length() : "Violation of: pos < |this|"; // TODO - fill in body }Provide a non-layered implementation of the secondary method
entrydefined inSequence. -
Add appropriate test cases for the
entrymethod toSequenceTestand test your implementation. -
Take a look at the
Standardmethods (newInstance,clear, andtransferFrom) inSequence3. We will discuss the details of these implementations later in the semester, but for now, design test cases to test these methods and add the test cases to your test fixture,SequenceTest.