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.

  1. Create a new Eclipse project by copying ProjectTemplate. Name the new project SetSecondaryMethods.
  2. 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.
  3. 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.
  4. In the test folder of this project create a new JUnit test fixture as practiced in an earlier lab. Name it SetSecondary1LTest.
  5. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. In SetSecondary1L.java, paste and implement the following instance method (for this method you can use only SetKernel methods—including inherited methods):
  2. In SetSecondary1LTest.java add appropriate test cases for the new method.
  3. 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.