Question: I need help completing this code import java.util.ArrayList; import java.lang.ClassCastException; /** * For this assignment a set is generally defined as a list of values

I need help completing this code

I need help completing this code import java.util.ArrayList; import java.lang.ClassCastException; /** *For this assignment a set is generally defined as a list ofvalues that is * sorted and does not contain any duplicate values.More specifically, a set * shall contain no pair of elements e1

import java.util.ArrayList;

import java.lang.ClassCastException;

/**

* For this assignment a set is generally defined as a list of values that is

* sorted and does not contain any duplicate values. More specifically, a set

* shall contain no pair of elements e1 and e2 such that e1.equals(e2), and at

* most one null element.

*/

public class Set

{

//

// TODO members

//

//

// TODO constructors

//

//

// TODO miscellaneous methods

//

public Object get(int index)

{

// TODO implementation

}

//

// TODO add() methods

//

//

// TODO remove() methods

//

public Set union(Set s)

{

}

public Set intersection(Set s)

{

}

public boolean subset(Set s)

{

}

public boolean superset(Set s)

{

}

public String toString()

{

String ret_string = "";

for (int i = 0; i

{

ret_string += _set_array.get(i).toString() + (i != _set_array.size() - 1 ? " " : "");

}

return ret_string;

}

public boolean equals(Object o) throws ClassCastException

{

if (!(o instanceof Set))

{

throw new ClassCastException();

}

Set s = (Set) (o);

for (int i = 0; i

{

if (!s.contains(_set_array.get(i)))

{

return false;

}

}

for (int i = 0; i

{

if (!_set_array.contains(s.get(i)))

{

return false;

}

}

return true;

}

}

In this project you will implement a Set class which represents a general collection of values. For this assignment, a set is generally defined as a list of values that is sorted and does not contain any duplicate values. More specifically, a set shall contain no pair of elements el and e2 such that el.equals (e2) and no null elements. Requirements To ensure consistency among all implementations there are some requirements that all implementations must maintain. * Your implementation should reflect the definition of a set at all times For simplicity, your set will be used to store Integer objects An ArrayList object must be used to represent the set. All methods that have an object parameter must be able to handle an input of null Methods such as Collections.sort that automatically sort a list may not be used. The Set class shall reside in the default package Recommendations There are deviations in program implementation that are acceptable and will not impact the overall functionality of the set class. A minimum size (initial capacity) may be specified for the ArrayList object. When elements are added, the ensureCapacity) method may be called to ensure that adding a new element can proceed . The trimToSize) method can be used to maintain a constant capacity equal to the number of elements in the set. Set Class Methods There are many methods that one would expect to be supported in a set class. This section will describe the interface of the set class. Unless specified, you will have to implement all of the described methods. Constructors Set o Description: constructs a set by allocating an ArrayList . Set (int size) Parameters: size - the desired size of the set. o o Description: constructs a set with an initial capacity of size * Set (int low, int high) o Parameters: low - an integer specifying the start value of a range of values

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!