Question
In Java: The SimpleSet Class: General Requirements: The SimpleSet class shall be written with Generics in order to allow Sets that can hold a variety
In Java:
The SimpleSet Class:
General Requirements:
The SimpleSet class shall be written with Generics in order to allow Sets that can hold a variety of different data types.
The SimpleSet classshall not allow duplicate items to be added to the set.
The SimpleSet class shall use Exception Handling to deal with indexes which are out of bounds, duplicate items, and sets that are full.
Use the IndexOutOfBounds exception from Java for out of bounds indices.
Create a DuplicateItemException class and use it when a duplicate item is added to the set.
Create a NotEnoughSpaceException class when an attempt is made to add an item to an already full SimpleSet or when the user tries to initialize a set with too many values.
NOTE: All of these exceptions should beunchecked exceptions.
Data Fields:
The SimpleSet class shall have a private data field which is an array of 10 elements to store each element of the Set. HINT: Take a look at the source code for ArrayList and see how they create the internal array for ArrayList. This array will be fixed at 10 and WILL NOT resize itself. We are creating a very simple set to hold only 10 items.
The SimpleSet class shall have a private data field that is an integer which holds the current size of the set. The size will increase as new items are added to the set.
The SimpleSet class shall haveno other data fields.
Constructors:
The SimpleSet class shall have a no argument constructor to create a new, empty instance of SimpleSet.
The SimpleSet class shall have another constructor that will accept a comma separated list of items to initialize the set. The following would be two examples of invoking this constructor:
SimpleSet s1 = new SimpleSet<>(1, 2, 3, 4, 5);
SimpleSet s2 = new SimpleSet<>("dog", "cat", "mouse");
NOTE: The comma separated lists can include anywhere between 1 and 10 values. If you do not remember how to create a parameter of this type, do some research on "variable-length parameter lists".
The SimpleSet class shall haveno other constructors.
Methods:
add: adds a new item to the end of the set.
contains: returns true or false depending on if the set already contains the item.
get:returns an item from the set at a specific index.
put:puts an item into the set at a specific index, replacing the old value.
size:returns the current size of the SimpleSet
toString: returns a String representation of a SimpleSet.
The Sorting Class:
Create a class called Sorting.
This class should be designed to prevent its instantiation.
This class has onestaticmethod calledsort. This method is ageneric methodthat should be designed to sort a SimpleSet.
This class should bound its generic to any class that uses the Comparable interface.
The sort method should implement the following pseudocode:
while the set is not sorted: for each item in the set: if next item > current item: swap current item and item
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started