Question: PracticeSet Class: Name class PracSet Data Fields: set: Your class shall have a data field called set. This data field shall be an array of
PracticeSet
Class:
Name class PracSet
Data Fields:
set: Your class shall have a data field called set. This data field shall be an array of integer values. This data field shall also be private with no getters or setters.
Constructors:
Your class shall have a default constructor which creates an empty set. This just means that your set data field will be an empty array. (You can do this by creating an array of size 0).
Your class shall have an additional constructor which will accept a comma separated list of integers as input to the constructor. Also note that this constructor can accept an array of integers as well. The following examples show how this constructor would be invoked:
PracticeSet set1 = new PracticeSet(23, 1, 2, 4, 78, 9);
PracticeSet set2 = new PracticeSet(myArray); //myArray is an existing array of integers.
Methods:
existsInSet: This method shall be a public method which accepts one integer as an argument. This method shall return true or false depending on whether or not the given value already exists within your set.
addToSet: This method shall be a public method which accepts one integer as an argument. The integer shall be added to the set, provided that the value does not already exist within the set. If the value already exists, display an error message.
Hint: use
existsInSet method
for help
PracticeSetUtils Class:
Name class PracticeSetUtils
Only contain static methods.
Data Fields:
No data fields.
Constructors:
This class shall have a no-arg (default) constructor which should have private visibility. This is to prevent the class from being instantiated.
Methods:
union: This method shall take two PracticeSet class instances as arguments, and returns a PracticeSet object which is the union of the two sets. This method shall be public and static.
Example {1, 2, 3, 4, 5} and {1, 3, 5, 6, 10} is {1, 2, 3, 4, 5, 6, 10}.
Hint: use addToSet method for help
intersection: This method shall take two PracticeSet class instances as arguments, and returns a PracticeSet object which is the intersection of the two sets. This method shall be public and static.
Example {1, 2, 3, 4, 5} and {1, 3, 5, 6, 10} is {1, 3, 5}.
If there is no intersection, then the result is the empty set.
Hint: use existsInSet method for
help
Main Class:
Test both classes' requirements
In JAVA, please and thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
