Create class called PracticeSet Class should always keep the values in the set i
ID: 3744553 • Letter: C
Question
Create class called PracticeSet
Class should always keep the values in the set in sorted order
When the values of a set are changed, re-sort the values
One data field called set, no getters or setters
Default constructor that creates empty array
Second constructor accepts comma separated list of integers and/or array of integers
Ex: PracticeSet set1 = new PracticeSet(1, 2, 3);
method exists(), should be public with one integer as an argument and return true or false if given value exists in set
method add(), should be public with one integer as an argument and add one integer to set if value doesnt already exist
Explanation / Answer
public class PracticeSet { private int[] set; public PracticeSet() { set = new int[0]; } public PracticeSet(int... arr) { set = new int[arr.length]; for(int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.