Question: import java.util.Arrays; /** * A class that implements the ADT set by using a resizable array. * The array is never full. * * @author

import java.util.Arrays; /** * A class that implements the ADT set by using a resizable array. * The array is never full. * * @author YOUR NAME * @version */ public class ArraySetWithArray> implements SetInterface { private T[] setOfEntries; private int numberOfEntries; private boolean initialized; private static final int DEFAULT_CAPACITY = 3; // Initial capacity of array private static final int MAX_CAPACITY = 10000; /** * Creates an empty array whose initial capacity is 3. */ public ArraySetWithArray() { //TODO Project2 } // end default constructor /** * Creates an empty array having a given initial capacity. * * @param capacity The integer capacity desired. */ public ArraySetWithArray(int capacity) { //TODO Project2 } // end constructor /** * Creates an array containing given entries. * * @param contents An array of objects. */ public ArraySetWithArray(T[] contents, int numberOfEntries) { //TODO Project2 // calls this.add fo not null elements } // end constructor /** * Throws an exception if the client requests a capacity that is too large. */ private void checkCapacity(int capacity) { if (capacity > MAX_CAPACITY) throw new IllegalStateException("Attempt to create a set whose capacity exceeds " + "allowed maximum of " + MAX_CAPACITY); } // end checkCapacity /** * Throws an exception if receiving object is not initialized. */ private void checkInitialization() { if (!this.initialized) throw new SecurityException("Uninitialized object used " + "to call an ArraySetWithArray method."); } // end checkInitialization /** * Adds a new entry to this array, rejecting duplicates and null entries. * * @param newEntry The object to be added as a new entry. * @return true if the addition is successful, or * false in case of null entry or duplicate to be added. */ public boolean add(T newEntry) { //TODO Project2 return false; //THIS IS A STUB } // end add /** * Checks if the set is full; if it is full doubles its size */ private void ensureCapacity() { //TODO Project2 } // end ensureCapacity /** * Retrieves all entries that are in this array. * * @return A newly allocated array of all the entries. */ public T[] toArray() { //TODO Project2 return null; //THIS IS A STUB } // end toArray /** * Sees whether this array is empty. * * @return True if this array is empty, or false if not. */ public boolean isEmpty() { //TODO Project2 return false; } // end isEmpty /** * Gets the number of entries currently in this array. * * @return The integer number of entries currently in the array. */ public int getCurrentSize() { //TODO Project2 return 0; //THIS IS A STUB } // end getCurrentSize /** * Tests whether this array contains a given entry. * * @param anEntry The entry to locate. * @return True if the array contains anEntry, or false if not. */ public boolean contains(T anEntry) { //TODO Project2 // utilize getIndexOf method return false; //THIS IS A STUB } // end contains /** * Locates a given entry within the array set. * Returns the index of the entry, if located, * or -1 otherwise. * Precondition: checkInitialization has been called. */ private int getIndexOf(T anEntry) { int index = -1; // TODO Project 2 return index; } // end getIndexOf /** * Removes all entries from this array. */ public void clear() { //TODO Project2 } // end clear /** * Removes one unspecified entry from this set. * * @return Either the removed entry if the removal * was successful, or null if not. */ public T remove() { //TODO Project2 return null; //THIS IS A STUB } // end remove /** * Removes one occurrence of a given entry from this array. * * @param anEntry The entry to be removed. * @return true if the removal was successful, or false if not. */ public boolean removeElement(T anEntry) { //TODO Project2 return false; } // end removeElement /** * Removes and returns the array entry at a given index. * * @param givenIndex index of the element to be removed * @return remove an element or null if no such entry exists */ private T removeEntry(int givenIndex) { //TODO Project2 return null; //THIS IS A STUB } // end removeEntry // // +++++++++++++++++++ NEW METHODS +++++++++++++++++++++++++++ // /** * Displays all entries in the set. * If the set is empty displays a message that the set is empty and display the capacity * if the set is not empty displays the number of elements, capacity and the content of the set */ public void displaySet() { //TODO Project2 // do not call toArray as this method has direct access to this.setOfEntries array } // end displaySet /** * Checks if the given set called other is the same as this set * * @param o the other set to be compared with * @return true both sets are the same */ public boolean equals(Object o) { boolean same; if (this == o) same = true; else if (o == null || getClass() != o.getClass()) same = false; else { ArraySetWithArray otherSet = (ArraySetWithArray) o; //TODO Project2 // one return statement per method please // first compare number of entries in both sets // only if the number of entries is the same // use a regular for loop to compare elements // stop the loop as soon as the first unequal pair is found } return false; // THIS IS A STUB } /** * Removes the largest entry from the this.setOfEntries * * @return - null if the set is empty * or the largest element */ public T removeMax() { // TODO Project2 // utilize removeEntry(givenIndex) method // one return statement per method please // utilize compareTo method return null; // THIS IS A STUB } // end removeMax /** * Removes all entries from this.setOfEntries that are larger than a given entry. * * @param anEntry the entry to be checked against */ public void removeAllLarger(T anEntry) { // TODO Project2 // must utilize only one loop that starts with the last element // utilize removeEntry(givenIndex) method // utilize compareTo method } // end removeAllLarger /** * Replaces the last entry in this setOfEntries with a given object. * * @param replacement the given object * @return the original entry in the setOfEntries that was replaced * or null if the set is empty or if the replacement is a duplicate */ public T replace(T replacement) { // TODO Project 2 // one return statement per method please return null; // THIS IS A STUB } // end replace /** * Creates a new set that combines the contents of this set and * a second given set without affecting the original two sets. * * @param otherSet the given set * @return a setOfEntries that is the union of the two sets */ public ArraySetWithArray union(ArraySetWithArray otherSet) { // TODO Project 2 // one return statement per method please return null; // THIS IS A STUB } // end union /** * Creates a new set that contains those objects that occur in both this * set and otherSet without affecting the original two sets. * * @param otherSet the given set * @return a set that is the intersection of the two sets */ public ArraySetWithArray intersection(ArraySetWithArray otherSet) { // TODO Project 2 // one return statement per method please // do NOT call contains, utilize getIndexOf(anEntry) instead return null; // THIS IS A STUB } // end intersection /** * Creates a new set of objects that would be left in this set * after removing those that also occur in a second given set * without affecting the original two sets. * * @param otherSet the given set * @return a set that is the difference of the two sets */ public ArraySetWithArray difference(ArraySetWithArray otherSet) { // TODO Project 2 // one return statement per method please // do NOT call contains, removeEntry(givenIndex) methods instead return null; // THIS IS A STUB } // end difference /** * Creates a new set of objects that are in this set and are less than a given object. * * @param anEntry a given object * @return a new set of objects that are in this set and are less than anObject */ public ArraySetWithArray getAllLessThan(T anEntry) { // TODO Project 2 // one return statement per method please // utilize compareTo method return null; // THIS IS A STUB } // end getAllLessThan /** * Checks if all the elements of the given set are also included in the other set * * @param otherSet set to check * @return returns true if all the elements of the given set are also included in the other set */ public boolean isSubset(ArraySetWithArray otherSet) { // TODO Project 2 // one return statement per method please // utilize difference method return false; // THIS IS A STUB } /** * Move the first element to be the last in the set by rotating the elements */ public void moveFirstToEnd() { // TODO Project2 } 

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!