Implement class ArraySet<E> class that implements the Set<E> interface below. It must allow any type of element in the collection. The add method must return true if the element was successfully added or false if that element already equals an element in the set. Because Set<E> extends Iterable<E>, your ArraySet<E> class will need to implement Iterator<E> iterator() and an inner class. Each method should run as specified in Big O notatation. Include a
unit test that makes assertions on all methods.
/**
* This interface specifies the methods for a Set ADT. Since Set<E> * extendsIterable<E> you must also add the unseen method Iterator<E> * iterator() to the *collection class.
*/
public interface Set<E> extends Iterable<E> {
// Return true if there are 0 elements in the bag.
// O(1)
public boolean isEmpty();
// Add element to this Set only if element does not equal
// another element already in this Set. Return false if
// element is in this Set, in which case, this Set does not change
// O(n)
public boolean add(E element);
// Return the number of elements in this set
// O(1)
public int size();
// Return the array capacity (the array's length)
// O(1)
public int capacity();
// Return true if element is in this set, or false if it is not
// O(n)
public boolean contains(E element);
// Remove element if it is in this set and return true,
// otherwise return false.
// O(n)
public boolean remove(E element);
// Return the union of this set and other
// O(n)
public Set<E> union(Set<E> other);
// Return the intersection of this set and other
// O(n)
public Set<E> intersection(Set<E> other);
}
Your ArrayList<E> class must have a constructor with two integer arguments. The first is the initial size of the 1D array. The second is the grow-by and shrink-by size in the add an remove methods respectively. Here is the beginning of the class.
public class ArraySet<E> implements Set<E> {
private Object[] data;
private int n;
private int delta;
// Construct an empty bag that can store any type of element.
// O(1)
public ArraySet(int initialCapacity, int growShrinkSize) {
data = new Object[initialCapacity];
n = 0;
delta = growShrinkSize;
}
// Add other methods here ...
}
When adding new elements, check to ensure there is room in the array data. If there is no unused array index, grow the array by delta elements. When removing existing elements, shrink the array by delta elements whenever there is room to add more than delta elements. In other words, leave no more than delta empty array locations at any time. The array must have from 0 through delta empty indexes at all times. The following assertions must pass.
This is a code/project that I have to develop on my own, but I don't even know where to start. I am using eclipse in developing this code and let's say I have a folder called project 1 then how many class do I have to create inside that project?? I know one class must exist for the
junit test, and what else do I need? I am predicting that I will need 2 other classes one is for the Set that extends the iteration. And one other else is for the ArrayList class that implements the set<E>, am I right?? I need further guidance to help me with this project. Thanks to those of you who are willing to help me out. Appreciate it.