In this project, you will implement a Set class that represents a general collection of values. For this  assignment,  a  set is generally defined as a  list of values that are 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. (in java) Requirements   among  all  implementations  there  are  some  requirements  that  all  implementations  must maintain.  • Your implementation should always reflect the definition of a set.  • 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. the sort that automatically sorts a list may not be used. Instead,  when a  successful addition of an element to the  Set is done,  you can ensure that the elements  inside the ArrayList object representing the Set remain sorted.  • The Set class shall reside in the default package.  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 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.  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.  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.  o 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)  o Parameters: s – a set of Integers.  o Description: determines if this set is a subset of s.  o 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.  Addition  • boolean add(Integer o)  o Parameters: o – element to be added to the 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 the set.  o Description: adds all elements

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In this project, you will implement a Set class that represents a general collection of values. For this 
assignment,  a  set is generally defined as a  list of values that are 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. (in java)
Requirements 
 among  all  implementations  there  are  some  requirements  that  all  implementations 
must maintain. 
• Your implementation should always reflect the definition of a set. 
• 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. the sort that automatically sorts a list may not be used. Instead, 
when a  successful addition of an element to the  Set is done,  you can ensure that the elements 
inside the ArrayList<Integer> object representing the Set remain sorted. 
• The Set class shall reside in the default package. 

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

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. 
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. 
o 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) 
o Parameters: s – a set of Integers. 
o Description: determines if this set is a subset of s. 
o 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. 
Addition 
• boolean add(Integer o) 
o Parameters: o – element to be added to the 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 the set. 
o Description: adds all elements

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY