CSci 2101 Problem set 4.

Due Friday October 21st at 11:59pm

You may work individually or in pairs.

Problem 1 (20 points)

Problem 14 on p. 239 specifies methods and behavior of a set. Implement and test a class Set<E> with the following differences from the one described in the book:

Submit your Set class and your test class. The quality of your testing will be a part of the grade.

Problem 2 (15 points): OurLinkedList equals method

Add an equals method to the OurLinkedList class. According to Java specification, equals method takes any object. It then checks if the parameter object is of the same type as this object (see instanceof check below). If the object passes the instanceof check, it is then typecast to OurLinkedList<E>. See more on instanceof here: http://www.java2s.com/Tutorial/Java/0060__Operators/TheinstanceofKeyword.htm.

The method is declared and starts as follows:


public boolean equals(Object obj) {
     //  checking that obj is an OurLinkedList
     if (!(obj instanceof OurLinkedList) ) return false;
     
     // typecasting obj to OurLinkedList
     OurLinkedList<E> thelist = (OurLinkedList<E>) obj;

     // the rest of your code goes here, use thelist variable:


}

Note that some of the elements in OurLinkedList may be null. If that's the case, the corresponding elements in both lists must be null for the two lists to be equal.

Test your method extensively, include all your test cases.

How to submit

Submit the java file(s) with your testing code by e-mail to me. The subject of the message must be 2101 Problem set 4. Make sure to CC your group partner(s) if any.


CSci 2101 course web site.