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
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 ArrayListStep 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