Question: Write a SquareSet class that implements Set . Implement all required methods as well as the add method. For all other optional methods follow the

Write a SquareSet class that implements Set . Implement all required methods as well as the add method. For all other optional methods follow the instructions in the Set API documentation found on the oracle website, think about what happens when a user calls an optional method which hasn't been implemented. If an invalid square is added, throw the InvalidSquareException you created in the previous homework. You may need to modify your InvalidSquareException class. Use an array as your backing store. Set implements Iterable . So youll also need to write a class that implements Iterator , an instance of which you should return from SquareSet s iterator method. Your Iterator class should be an inner class.

Points: 5 points: no-arg contsructor creates an instance of SquareSet

5 points: add method adds a valid Square not already in the set

5 points: add method throws exceptoin for attempt to add and invalid Square

5 points: add method does not add a valid Square already in the set

10 points: contains

10 points: containsAll

10 points: equals

10 points: hashCode

10 points: isEmpty

10 points: iterator

5 points: size

5 points: toArray

10 points: toArray(T[] a) Extra:

10 points: addAll adds all Square s in argument if all squares are valid

10 points: addAll throws InvalidSquareExceptoin and adds no Square s from argument if any Square in argument is invalid

10 points: addAll adds Square s from arguemnt that are not already in set but not any Square s that are already in the set

10 points: remove removes argument from set

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!