Developing a Utility Array The challenge in the project is developing algorithms that accomplishes basic operations over
Fantastic news! We've Found the answer you've been seeking!
Question:
Developing a Utility Array
The challenge in the project is developing algorithms that accomplishes basic operations over an array of integer numbers.
The three operations are:
- Find the minimum (smallest) value that appears in the array
- Find the maximum (largest) value that appears in the array
- Determine the number of unique values that appear in the array
Develop an algorithm for each of those tasks. The algorithms should work for any size of array. If the array is empty (i.e., doesn't include any elements/values) the algorithm should output a zero.
Keep in mind that like any computational problem there are several approaches to achieve a solution. For this programming checkpoint you will need to utilize loops and conditional statements.
In VSCode create a class with the following requirements:
- Class name is ArrayUtil
- Has an integer array field named intArray
- A default constructor
- A constructor that accepts one argument for the array field and assigns that argument to the appropriate field. You may assume that only valid values (see 6a below) will be used to test the constructor.
- An accessor for the field.
- A mutator for the field.
- A method called minValue that does not accept any arguments and finds the minimum (smallest) value in the integer array and returns that value.
- A method called maxValue that does not accept any arguments and finds the maximum (largest) value in the integer array and returns that value.
- A method called countUniqueIntegers that does not accept any arguments and determines the number of unique values that appear in the array and returns that value. (i.e., count of the number of unique integer values in an array).
- Add a method that will return an array that will only contain the unique values of the original array (i.e., remove duplicates)
- Add a method that given two element positions (indices) in the array swaps the two elements with each other.
- Add a method that determines whether the array is sorted or not. This method should allow for specifying whether the sorting to be determined is in descending or ascending order.
Related Book For
Posted Date: