You may work individually or in pairs.
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:
Set<E>
, where E is
the type of the elements in the set. All methods that take or
return elements should take or return objects of type E.ArrayList
and not an array to
store its elements. createSet
just write a
constructor that creates an empty set.Submit your Set class and your test class. The quality of your testing will be a part of the grade.
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.
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.