4. Consider a member method for the Set ADT called singletons(). Given a set A = {XO, X1,...,xn), the singleton set of A is a collection of sets (i.e. a set of sets), each containing only one element of A: S = {{xo}, {x1},...., {x}}. The prototype for the method is as follows: public Set
> singletonSets() Add this method to the Set interface, then implement it in the StaticSet and DynamicSet classes. For the DynamicSet class, simply return the result generated by the StaticSet instance. Test your code! Hint: Set Set> result = new StaticSet>(this.size()); @Override public Set> singletonSets() { return null; 3 public interface Set extends Iterable 1 MOOOOOO public boolean add(E obj); public boolean isMember(E obj) public boolean remove(E obj); public boolean is Empty(); public int size(); public void clear(); public Set union(Set S2): public Set difference(Set 52); public Set intersection(Set S2): public boolean isSubSet(Set S2): public boolean equals(Set $2); public Set> singletonsets (: 16 import java.util.Iterator;0 public class StaticSet implements Set { // current number of elements in set, private int currentSize; w 100 // array of elements private E elements[]; private static final int DEFAULT_SET_SIZE = 10; WNEO00 public staticSet(int maxCapacity) { if (maxCapacity implements Iterator { private int current Position; public SetIterator() this.currentPosition = 0; 6 CO O public class DynamicSet implements Set { // static set private StaticSet theSet; // current max capacity private int maxCapacity; private static final int DEFAULT_SET_SIZE = 10; public DynamicSet(int initialCapacity) { this.theSet = new StaticSet(initialCapacity); this.maxCapacity = initialCapacity; @Override public Iterator iterator() { return theSet.iterator(); @Override public boolean add(E obj) { if (this.isMember(obj)) // Avoid extending the set unnecessarily return false; if (this.maxCapacity == this.theSet.size()) this.maxCapacity *= 2; StaticSet newSet = new StaticSet(this.maxCapacity); copySet(theSet, newSet); this.theSet = newSet; return this.theSet.add(obj); private void copySet(Set src, Set dst) { for (object obj: src) dst.add(CE) obi); }