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 e1 and e2 such that e1.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) o Parameters: size - the desired size of the set. 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. high – an integer specifying the end value of a range of values. o Description: constructs a set of Integer objects containing all the inclusive values from the range low…high. The default size of the set must accommodate this mode of construction. Addition • boolean add(Integer o) o Parameters: o – element to be added to this set. o Description: if o is not in this set, o is added to this set. o Returns: TRUE if the element is successfully added to this set. FALSE if the element is not added to this set. • int add(Integer[] s) o Parameters: s – array of elements to be added to this set. o Description: adds all elements of s to this set. o Returns: the number of elements successfully added to this set. Removal • Integer remove(Integer o) o Parameters: o – element to be deleted from this set. o Description: if o is in this set, the element is deleted. o Returns: the object that will be removed from this set. If the element is not contained in this set, null is returned. • int remove(Set s) o Parameters: s – set of elements to be deleted from this set. o Description: deletes all elements of s from this set. o Returns: the number of elements successfully deleted from this set. Miscellaneous • boolean contains(Integer o) o Parameters: o – the element to be searched for in this set. o Description: determines whether the given element is in this set. o Returns: TRUE or FALSE whether o is in this set. • void clear() o Description: Removes all the elements from this set. • boolean isEmpty() o Description: determines whether this set contains any elements. In Java please

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 e1 and e2 such that

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

• Set(int size)

o Parameters: size - the desired size of the set.

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. high – an integer specifying the end value of a range of values.

o Description: constructs a set of Integer objects containing all the inclusive values from

the range low…high. The default size of the set must accommodate this mode of

construction.

Addition

• boolean add(Integer o)

o Parameters: o – element to be added to this set.

o Description: if o is not in this set, o is added to this set.

o Returns:

 TRUE if the element is successfully added to this set.

 FALSE if the element is not added to this set.

• int add(Integer[] s)

o Parameters: s – array of elements to be added to this set.

o Description: adds all elements of s to this set.

o Returns: the number of elements successfully added to this set.

Removal

• Integer remove(Integer o)

o Parameters: o – element to be deleted from this set.

o Description: if o is in this set, the element is deleted.

o Returns: the object that will be removed from this set. If the element is not contained

in this set, null is returned.

• int remove(Set s)

o Parameters: s – set of elements to be deleted from this set.

o Description: deletes all elements of s from this set.

o Returns: the number of elements successfully deleted from this set.

Miscellaneous

• boolean contains(Integer o)

o Parameters: o – the element to be searched for in this set.

o Description: determines whether the given element is in this set.

o Returns: TRUE or FALSE whether o is in this set.

• void clear()

o Description: Removes all the elements from this set.

• boolean isEmpty()

o Description: determines whether this set contains any elements.

In Java please

4:18 Sprint
A LTE ll 75%
o Returns: TRUE or FALSE whether this set contains zero elements.
int size ()
o Description: determines the number of elements in this set.
o Returns: the number of elements in this set.
Integer get (int index)
o
Parameters: index - the integer index of the desired element in this set.
o Description: returns the Object at the specified index if the index is valid.
o Returns: the Object at the specified index; null if the specified index is out of
range: (index < 0 || index >= size ()).
Union
Set union (Set s)
o Parameters: s-a set of Integers.
o Description: constructs and returns a new Set object that contains the objects in either
this set or the input set s.
Returns: a newly constructed Set object containing the union of the sets.
Intersection
Set intersection (Set s)
o Parameters: s - a set of Integers.
o Description: constructs and returns a new Set object that contains the objects in both
this set and the input set s.
o Returns: a newly constructed Set object containing the intersection of the sets.
Other Methods
boolean subset (Set s)
o Parameters: s - a set of Integers.
o Description: determines if this set is a superset of s.
o Returns: TRUE or FALSE if all the elements of s are contained in this set.
o Notes: This method can be implemented easily using other methods described in this
assignment. null should be considered a subset of any other set.
boolean superset (Set s)
Parameters: s - a set of Integers.
o Description: determines if this set is a subset of s.
Returns: TRUE or FALSE if all the elements of this set are contained in s.
o Notes: This method can be implemented easily using other methods described in this
assignment. null can only be considered a superset of the null set. However, this
cannot conceivably happen when using an instance of the Set class.
Transcribed Image Text:4:18 Sprint A LTE ll 75% o Returns: TRUE or FALSE whether this set contains zero elements. int size () o Description: determines the number of elements in this set. o Returns: the number of elements in this set. Integer get (int index) o Parameters: index - the integer index of the desired element in this set. o Description: returns the Object at the specified index if the index is valid. o Returns: the Object at the specified index; null if the specified index is out of range: (index < 0 || index >= size ()). Union Set union (Set s) o Parameters: s-a set of Integers. o Description: constructs and returns a new Set object that contains the objects in either this set or the input set s. Returns: a newly constructed Set object containing the union of the sets. Intersection Set intersection (Set s) o Parameters: s - a set of Integers. o Description: constructs and returns a new Set object that contains the objects in both this set and the input set s. o Returns: a newly constructed Set object containing the intersection of the sets. Other Methods boolean subset (Set s) o Parameters: s - a set of Integers. o Description: determines if this set is a superset of s. o Returns: TRUE or FALSE if all the elements of s are contained in this set. o Notes: This method can be implemented easily using other methods described in this assignment. null should be considered a subset of any other set. boolean superset (Set s) Parameters: s - a set of Integers. o Description: determines if this set is a subset of s. Returns: TRUE or FALSE if all the elements of this set are contained in s. o Notes: This method can be implemented easily using other methods described in this assignment. null can only be considered a superset of the null set. However, this cannot conceivably happen when using an instance of the Set class.
4:18 M
A LTE ll 75%
Supplied Methods
Besides the interface specification described above, there are other methods that have been provided; feel
free to use them as required in your implementation and testing. Do not modify these methods.
• String tostring ()
o Description: provides a means of viewing the values contained within the Set object.
o Returns: a String representation of this set.
o Notes: It is important that this method remain unmodified since it will be used for
evaluation purposes. It has been provided for debugging purposes.
boolean equals (Object o)
o Parameters: s -a set of values to compare against this set.
o Description: determines whether the content of o equals this set.
o Returns: TRUE or FALSE whether o is an instance of class Set and contains all
elements of this set.
o Notes: It is important that this method remain unmodified since it will be used for
evaluation purposes. It has been provided for debugging purposes.
Testing
public static void main (String args[])
o Parameters: args – unused in this implementation.
o Description: this is a method that will be part of a test class SetTester.
o Notes: A complete testing class (SetTester) used for grading has been provided to
expedite development. This method can be modified as desired; you will not have to
submit this file.
Transcribed Image Text:4:18 M A LTE ll 75% Supplied Methods Besides the interface specification described above, there are other methods that have been provided; feel free to use them as required in your implementation and testing. Do not modify these methods. • String tostring () o Description: provides a means of viewing the values contained within the Set object. o Returns: a String representation of this set. o Notes: It is important that this method remain unmodified since it will be used for evaluation purposes. It has been provided for debugging purposes. boolean equals (Object o) o Parameters: s -a set of values to compare against this set. o Description: determines whether the content of o equals this set. o Returns: TRUE or FALSE whether o is an instance of class Set and contains all elements of this set. o Notes: It is important that this method remain unmodified since it will be used for evaluation purposes. It has been provided for debugging purposes. Testing public static void main (String args[]) o Parameters: args – unused in this implementation. o Description: this is a method that will be part of a test class SetTester. o Notes: A complete testing class (SetTester) used for grading has been provided to expedite development. This method can be modified as desired; you will not have to submit this file.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 8 steps with 7 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education