Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Outcomes: Implement an ADT (specifically a resizable array-based implementation of the Set ADT) Test a class Naming requirements (not following any of these may result

Outcomes:

Implement an ADT (specifically a resizable array-based implementation of the Set ADT)

Test a class

Naming requirements (not following any of these may result in a score of 0):

The Eclipse project name must be Project2.

You will have write exactly two source code files: ResizableArraySet.java and SetTester.java

You will also need to include the Set interface as specified in SetInterface.java. Do not modify this file. Your resizable array set must implement this interface.

You will use the default package (this means there should be no package statements in any of your files).

Your assignment is to:

1. In a class named ResizableArraySet, implement the abstract data type Set by implementing all of the methods in the interface found in SetInterface.java. Your implementation will use a resizable array of int values that doubles in size any time an item is added when the array is already full. Do not use Java's ArrayList. You should simply work with an array, and handle the array resizing on your own.

2. The only instance variables should be the array of int values and a counter for the number of entries in the set.

3. There should be two constructors: a. A constructor with no parameters. By default this should use an array instance variable with a starting size of 10. b. A constructor with an int parameter specifying the starting size of the array instance variable.

4. SetTester should thoroughly test the methods and constructors in the ResizableArraySet class. It should utilize the main() method and helper methods to print to the screen what is being tested, what results are expected, and then show the actual results. This should not involve any interaction from the user. Do not ask the user to enter input. Just run test cases.

Output should look something like this:

Creating an empty set and adding three items 4 9 2

Expecting to see 4 9 2

Result 4 9 2

Removing 4 and expecting to see 9 2

Result 9 2

Your test code should not require me to look at your source code. I should know, by running your tester, what is being tested, what results are expected, and what the actual results are. I will be looking for:

Thoroughness (test all constructors and methods)

Organization (keep related tests together)

Readability (use single blank lines in appropriate places to break your code into "chunks" so it's easy to know when one part of your testing is done and the next part begins). The Arrays.toString() is a useful way to display the contents of an array. Feel free to use it to output your results.

HERE IS THE INTERFACE FILE:

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 Integer.MIN_VALUE.

*/

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

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

Students also viewed these Databases questions