Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

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

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

What is nonfinancial compensation?

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago

Question

What are some of the possible scenes from our future?

Answered: 1 week ago