Lab: Set Secondary Methods
Objective
In this lab you will practice implementing instance
methods for the Set family of components. In particular,
you will implement the add and remove secondary
methods in a new class that extends Set1L.
Setup
Follow these steps to set up a project for this lab.
- Create a new Eclipse project by copying ProjectTemplate.
Name the new project SetSecondaryMethods.
- Open the src folder of this project and then open
(default package). As a starting point you can use any of
the Java files. Rename it SetSecondary1L and delete the
other files from the project.
- Follow the link to SetSecondary1L.java,
select all the code on that page and copy it to the clipboard;
then open the SetSecondary1L.java file in Eclipse and
paste the code to replace the file contents. Save the file.
- In the test folder of this project create a new
JUnit test fixture as practiced in an
earlier lab. Name it SetSecondary1LTest.
- Follow the link to SetSecondary1LTest.java,
select all the code on that page and copy it to the clipboard;
then open the SetSecondary1LTest.java file in Eclipse and
paste the code to replace the file contents. Save the file.
Method
- In SetSecondary1L.java, complete the body of the remove
method. The contract is available in the Set
component documentation. For this method you can use any of
the Set methods (except for calling the remove(Set<T>
s) method inherited from Set1L). In particular, you can
use the remove(T x) SetKernel method.
- Run the SetSecondary1LTest test fixture and test
your implementation of remove. Of course, some of the
test cases for add will fail because the operation has
not been implemented yet. Ignore those for now. Fix any problems
in remove revealed by the corresponding test cases.
- Back in SetSecondary1L.java, complete the body of
the add method. The contract is available in the Set
component documentation. For this method you can use any of
the Set methods (except for calling the add(Set<T>
s) method inherited from Set1L). In particular, you can
use the add(T x) SetKernel method.
- Again run the SetSecondary1LTest test fixture and
test your implementation of add. Fix any problems in add
revealed by the corresponding test cases.
Additional Activities
- In SetSecondary1L.java, paste and implement the
following instance method (for this method you can use only
SetKernel methods—including inherited methods):
- In SetSecondary1LTest.java add appropriate test
cases for the new method.
- Run the SetSecondary1LTest test fixture and test
your implementation of isSubset. Fix any problems in isSubset
and in SetSecondary1LTest until you are confident that
your implementation of isSubset works and that your test
cases adequately test the method's behavior.