Question: 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

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. 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. You will want to implement this method first since it will help you to implement some of the methods to follow. HINT: You will need to account for when the set may be empty. 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 1: Use the existsInSet method that you wrote previously to help implement this method. HINT 2: Since we cannot change the size of an existing array, you will need to create a new array with the current size + 1, and then copy the existing values to the new array and add the new value to the end. Be sure to update your set data field to refer to the new array and not the old one. removeFromSet: This method shall be a public method which accepts one integer as an argument. This integer shall be a value that will be removed from the set. (Note: This is not the index to remove, but the actual value you want to remove.) HINT 1: Make sure the value to be removed actually exists. If it does not, display an error message to the user and do not remove anything. Use the existsInSet method that you wrote previously to help implement this method. HINT 2: Since we cannot change the size of an existing array, you will need to create a new array with the current size - 1, and then copy the existing values to the new array, but exclude the value to be removed. Be sure to update your set data field to refer to the new array and not the old one.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!