Description
This assignment focuses on implementing the methods of a class much like
java.util.Arrays. The Selector.java file defines a class with static methods designed
to provide useful functionality on arrays, with the common theme of selecting values in
an array with particular properties. Each method of Selector is clearly specified, is
independent of the other methods in the class, and is designed to provide relatively
simple functionality. So, this is a great context in which to practice systematic,
disciplined development and test-based verification.
The Selector class
You must correctly implement all the method bodies of the provided Selector class.
Your implementation must adhere exactly to the API of the Selector class, as described
in the provided source code comments and as described below.
A brief description of each method is provided below, along with examples of its use.
Refer to the Selector.java source code file for the complete specification of each
method’s required behavior.
The min method
This method selects the minimum value from a given array. Examples:
The max method
This method selects the maximum value from a given array. Examples:
The kmin method
This method selects the k-th minimum (smallest) value from a given array. A value is the
k-th minimum if and only if there are exactly k – 1 distinct values strictly less than it in the
array. Note that kmin(a, 1) == min(a) and kmin(a, a.length()) == max(a). Examples:
The kmax method
This method selects the k-th maximum (largest) value from a given array. A value is the
k-th maximum if and only if there are exactly k – 1 distinct values strictly greater than it in
the array. Note that kmax(a, 1) == max(a) and kmax(a, a.length()) == min(a).
Examples:
The range method
This method selects all values from a given array that are greater than or equal to low
and less than or equal to high.
The floor method
This method selects from a given array the largest value that is less than or equal to
key. Examples:
The ceiling method
This method selects from a given array the smallest value that is greater than or equal
to key. Examples:
Notes and Other Requirements
● The Selector.java source code file is provided in the startercode folder in
Vocareum. You can download Selector.java from Vocareum and work on your
local machine.
● The comments provided in Selector.java describe the required behavior of each
method.
● The constructor of the Selector class has been written for you and it must not be
changed in any way.
● You may add any number of private methods that you like, but you may not add
any public method or constructor, nor may you change the signature of any
public method or constructor.
● You must not add any fields, either public or private, to the Selector class.
● The java.util.Arrays class has been imported for you. You are free to delete
this import statement if you do not use any methods from the Arrays class in your
solutions.
● You may not add any other import statement, and you may not use another
resource from the java.util package. The penalty for violating this constraint will
be a deduction of points up to 50% of the total points available on the
assignment.
● You may not use sorting in any method, except for kmin and kmax. The penalty for
violating this constraint will be a deduction of points up to 50% of the total points
available on the assignment.
● You do not have to use sorting in kmin and kmax, but doing so makes the solution
more straightforward. If you choose to use sorting in these two methods, I
suggest that you use the sort(int[]) method from the java.util.Arrays class.