Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here are the .java files you will need : ------------------------------------------------------------------------------------------------------------------------------ ArraySet.java : --------------------------------------------------------------------------------------------------------------------------------------- import java.util.Iterator; import java.util.NoSuchElementException; /** * ArraySet.java. * * Provides an implementation

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Here are the .java files you will need :

------------------------------------------------------------------------------------------------------------------------------ArraySet.java :---------------------------------------------------------------------------------------------------------------------------------------

import java.util.Iterator; import java.util.NoSuchElementException;

/** * ArraySet.java. * * Provides an implementation of the Set interface using an * array as the underlying data structure. Values in the array * are kept in ascending natural order and, where possible, * methods take advantage of this. Many of the methods with parameters * of type ArraySet are specifically designed to take advantage * of the ordered array implementation. * * @author Your Name (yourTigerMail@auburn.edu) * @author Dean Hendrix (dh@auburn.edu) * @version 2016-03-01 * */ public class ArraySet> implements Set {

//////////////////////////////////////////// // DO NOT CHANGE THE FOLLOWING TWO FIELDS // //////////////////////////////////////////// T[] elements; int size;

//////////////////////////////////// // DO NOT CHANGE THIS CONSTRUCTOR // //////////////////////////////////// /** * Instantiates an empty set. */ @SuppressWarnings("unchecked") public ArraySet() { elements = (T[]) new Comparable[1]; size = 0; }

/////////////////////////////////// // DO NOT CHANGE THE SIZE METHOD // /////////////////////////////////// /** * Returns the current size of this collection. * * @return the number of elements in this collection. */ public int size() { return size; }

////////////////////////////////////// // DO NOT CHANGE THE ISEMPTY METHOD // ////////////////////////////////////// /** * Tests to see if this collection is empty. * * @return true if this collection contains no elements, * false otherwise. */ public boolean isEmpty() { return size == 0; }

/////////////////////////////////////// // DO NOT CHANGE THE TOSTRING METHOD // /////////////////////////////////////// /** * Return a string representation of this ArraySet. * * @return a string representation of this ArraySet */ @Override public String toString() { if (isEmpty()) { return "[]"; } StringBuilder result = new StringBuilder(); result.append("["); for (T element : this) { result.append(element + ", "); } result.delete(result.length() - 2, result.length()); result.append("]"); return result.toString(); }

/** * Ensures the collection contains the specified element. * No specific order can be assumed. Neither duplicate nor null * values are allowed. * * @param element The element whose presence is to be ensured. * @return true if collection is changed, false otherwise. */ public boolean add(T element) { return false; }

/** * Ensures the collection does not contain the specified element. * If the specified element is present, this method removes it * from the collection. * * @param element The element to be removed. * @return true if collection is changed, false otherwise. */ public boolean remove(T element) { return false; }

/** * Searches for specified element in this collection. * * @param element The element whose presence in this collection * is to be tested. * @return true if this collection contains the specified element, * false otherwise. */ public boolean contains(T element) { return false; }

/** * Tests for equality between this set and the parameter set. * Returns true if this set contains exactly the same elements * as the parameter set, regardless of order. * * @return true if this set contains exactly the same elements * as the parameter set, false otherwise */ public boolean equals(Set s) { return false; }

/** * Tests for equality between this set and the parameter set. * Returns true if this set contains exactly the same elements * as the parameter set, regardless of order. * * @return true if this set contains exactly the same elements * as the parameter set, false otherwise */ public boolean equals(ArraySet s) { return false; }

/** * Returns a set that is the union of this set and the parameter set. * * @return a set that contains all the elements of this set and * the parameter set */ public Set union(Set s) { return null; }

/** * Returns a set that is the union of this set and the parameter set. * * @return a set that contains all the elements of this set and * the parameter set */ public Set union(ArraySet s) { return null; }

/** * Returns a set that is the intersection of this set * and the parameter set. * * @return a set that contains elements that are in both * this set and the parameter set */ public Set intersection(Set s) { return null; }

/** * Returns a set that is the intersection of this set and * the parameter set. * * @return a set that contains elements that are in both * this set and the parameter set */ public Set intersection(ArraySet s) { return null; }

/** * Returns a set that is the complement of this set and * the parameter set. * * @return a set that contains elements that are in this * set but not the parameter set */ public Set complement(Set s) { return null; }

/** * Returns a set that is the complement of this set and * the parameter set. * * @return a set that contains elements that are in this * set but not the parameter set */ public Set complement(ArraySet s) { return null; }

/** * Returns an iterator over the elements in this ArraySet. * No specific order can be assumed. * * @return an iterator over the elements in this ArraySet */ public Iterator iterator() { return null; }

/** * Returns an iterator over the elements in this ArraySet. * The elements are returned in descending order. * * @return an iterator over the elements in this ArraySet */ public Iterator descendingIterator() { return null; }

/** * Returns an iterator over the members of the power set * of this ArraySet. No specific order can be assumed. * * @return an iterator over members of the power set */ public Iterator> powerSetIterator() { return null; }

}

---------------------------------------------------------------------------------------------------------------------------------------Set.java-------------------------------------------------------------------------------------------------------------------------------------

import java.util.Iterator;

/** * A collection that implements set behavior. * * @author Dean Hendrix (dh@auburn.edu) * @version 2016-03-01 * */

public interface Set extends Iterable {

/** * Ensures the collection contains the specified element. * No specific order can be assumed. Neither duplicate nor null * values are allowed. * * @param element The element whose presence is to be ensured. * @return true if collection is changed, false otherwise. */ boolean add(T element);

/** * Ensures the collection does not contain the specified element. * If the specified element is present, this method removes it * from the collection. * * @param element The element to be removed. * @return true if collection is changed, false otherwise. */ boolean remove(T element);

/** * Searches for specified element in this collection. * * @param element The element whose presence in this collection is to be tested. * @return true if this collection contains the specified element, false otherwise. */ boolean contains(T element);

/** * Returns the current size of this collection. * * @return the number of elements in this collection. */ int size();

/** * Tests to see if this collection is empty. * * @return true if this collection contains no elements, false otherwise. */ boolean isEmpty();

/** * Tests for equality between this set and the parameter set. * Returns true if this set contains exactly the same elements * as the parameter set, regardless of order. * * @return true if this set contains exactly the same elements as the parameter set, false otherwise */ boolean equals(Set s);

/** * Returns a set that is the union of this set and the parameter set. * * @return a set that contains all the elements of this set and the parameter set */ Set union(Set s);

/** * Returns a set that is the intersection of this set and the parameter set. * * @return a set that contains elements that are in both this set and the parameter set */ Set intersection(Set s);

/** * Returns a set that is the complement of this set and the parameter set. * * @return a set that contains elements that are in this set but not the parameter set */ Set complement(Set s);

/** * Returns an iterator over the elements in this collection. * No specific order can be assumed. * * @return an iterator over the elements in this collection */ Iterator iterator();

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Is the page design inviting and accessible? (424)

Answered: 1 week ago

Question

What is the percentage of employees who have adopted children?

Answered: 1 week ago