Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Considering the following requirements write down a Java program: 30 (1) SpecialNumbers class represents a set of unique integers. Its capacity can be specified
2. Considering the following requirements write down a Java program: 30 (1) SpecialNumbers class represents a set of unique integers. Its capacity can be specified at the time of creation and cannot be altered subsequently. It maintains the actual length of the set (i.e., the number of the unique integers). It incorporates a method referred to as conditionalAdd that adds the specified new element to the set by following: (i) If the new element is unique in the set, the new element is added and the length of the set is increased. (ii) The sequence of the added numbers is internally maintained. (iii) It throws an IllegalState Exception if the new element to be added is already present or the set has already attained its maximum capacity. (2) The getLength() method tells how many elements are present. (3) The getCapacity() method tells how many elements in total can be stored. (4) The nth method returns the n-th value after arranging all the elements in ascending (increasing) order. If n = 1, it returns the lowest number. If n = 2, it returns the second lowest number If n = 3, it returns the third lowest number, etc. If n = length, it returns the highest number. The method corrects any out-of-boundary values of n to be as the boundary values. That is, if n length, it returns the highest number. (5) In order to support a subsequence of the numbers, the following new constructor and method are added to the SpecialNumbers class. (a) The new constructor creates a SpecialNumbers with the specified int array as numbers. (b) The subNumbers method creates a SpecialNumbers containing a subsequence of this SpecialNumbers. Arguments start and end specify the first and last characters, respectively, in the subsequence. If start and/or end are out-of-range values, the values are adjusted following the nth method convention. An IllegalArgumentException is thrown if start is greater than end after the adjustment The functions of Java's built in Arrays class and methods you can use in your program: // Create a copy with mentioned quantity of elements from beginning int[] temp = Arrays.copyOf(numbers, length); // Sorts the array in ascending order Arrays.sort(temp); //Copies the specified range ("from" inclusive and "to" exclusive) of the specified array into a /ew array. copyOfRange(int[] original, int from, int to)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started