Question: public interface SetInterface { /** * Gets the current number of entries in this set. * * @return The integer number of entries currently in

public interface SetInterface {

/**

* Gets the current number of entries in this set.

*

* @return The integer number of entries currently in the set.

*/

public int getSize();

/**

* Sees whether this set is empty.

*

* @return True if the set is empty, or false if not.

*/

public boolean isEmpty();

/**

* Adds a new entry to this set, avoiding duplicates.

*

* @param newEntry

* The integer to be added as a new entry.

* @return True if the addition is successful, or false if the item already

* is in the set.

*/

public boolean add(int newValue);

/**

* Removes a specific entry from this set, if possible.

*

* @param anEntry

* The entry to be removed.

* @return True if the removal was successful, or false if not.

*/

public boolean remove(int aValue);

/**

* Removes one unspecified entry from this set, if possible.

*

* @return Either the removed entry, if the removal was successful, or null.

*/

public int remove();

/** Removes all entries from this set. */

public void clear();

/**

* Tests whether this set contains a given entry.

*

* @param anEntry

* The entry to locate.

* @return True if the set contains anEntry, or false if not.

*/

public boolean contains(int anEntry);

/**

* Computes the union of this set with a given set

*

* @param anotherSet

* another set

* @return the union of this set with anotherSet

*/

public SetInterface union(SetInterface anotherSet);

/**

* Computes the intersection of this set with a given set

*

* @param anotherSet

* another set

* @return the intersection of this set with anotherSet

*/

public SetInterface intersection(SetInterface anotherSet);

/**

* Computes the elements in this set except for those that are also in anotherSet

*

* @param anotherSet

* another set

* @return the result of removing all elements of this set that are in anotherSet

*/

public SetInterface difference(SetInterface anotherSet);

/**

* Retrieves all entries that are in this set.

*

* @return A newly allocated array of all the entries in the set, where the

* size of the array is equal to the number of entries in the set.

*/

public int[] toArray();

} // end SetInterface

public class ResizableArraySet implements SetInterface {

private int [] data;

private int size;

public static int DEFAULT_CAPACITY = 10;

public ResizableArraySet() {

data = new int[DEFAULT_CAPACITY];

size = 0;

}

public ResizableArraySet(int startingSize) {

data = new int[startingSize];

size = 0;

}

@Override

public int getSize() {

// TODO Auto-generated method stub

return size;

}

@Override

public boolean isEmpty() {

// TODO Auto-generated method stub

return size == 0;

}

@Override

public boolean add(int newValue) {

if(contains(newValue)) {

return false;

}

if(size >= data.length) {

return false;

} else {

data[size] = newValue;

size++;

return true;

}

}

@Override

public boolean remove(int aValue) {

for(int i = 0; i < size; i ++) {

if(aValue == (data[i])) {

data[i] = data[size - 1];

data[size - 1] = 0;

size --;

}

}

return true;

}

@Override

public int remove() {

int Last = size - 1;

data[Last] = 0;

return 0;

}

@Override

public void clear() {

while(!isEmpty()) {

remove();

}

}

@Override

public boolean contains(int anEntry) {

for(int i = 0; i < size; i++) {

if(anEntry == (data[i]))

return true;

}

return false;

}

@Override

public SetInterface union(SetInterface anotherSet) {

// TODO Auto-generated method stub

return null;

}

@Override

public SetInterface intersection(SetInterface anotherSet) {

// TODO Auto-generated method stub

return null;

}

@Override

public SetInterface difference(SetInterface anotherSet) {

// TODO Auto-generated method stub

return null;

}

@Override

public int[] toArray() {

// TODO Auto-generated method stub

return null;

}

}

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!