public class DataProcessor { /** This method should return true if and only if every element in the * input array is in ascending order, meaning that none of the values * in the array are smaller than the previous element, and false * otherwise. For example, the array {1, 2, 5, 5, 6, 7, 8, 8, 8} * would be in order. An empty array is considered in order as well. */ public static boolean inOrder(int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** This method will return the smallest value found in the array. For * example, for the array {4, 2, 3, 1, 5, 1}, the value 1 will be * returned. If the array is empty, then the built-in constant * Integer.MAX_VALUE may be returned. */ public static int smallest(int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** This method will return the smallest value found in the array which * is larger than the input n. For example, for the input n=2 and the * array {4, 2, 3, 1, 5, 1}, the value 3 will be returned. If no such * value exists, then the method will return the value n. */ public static int smallestGreaterThanN(int n, int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** Return the total number of distinct values contained in the * input array. For example, the array {2, 2, 5, 1, 7, 4, 7} has * 5 distinct values (the numbers 1, 2, 4, 5, and 7). * * Hint: calls to smallest() and smallestGreaterThanN() may help * you solve this. */ public static int numDistinct(int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** Determines the number of times element v occurs within the array * of values. For example, in the array {1, 2, 5, 5, 3, 2}, the value * v=2 occurs twice. */ public static int numOccurrences(int v, int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** Determines the number of elements from the array of values which * have a value within the range [a, b) (that is, between a and b, * including a but not including b). For example, if the input array * is {1, 2, 3, 4, 2, 3, 4, 3, 4, 4} with a=2 and b=4, the result would * be 5 (because there are two 2's and three 3's). */ public static int numInRange(int a, int b, int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** Finds the arithmetic mean (the average) of the list of numbers. For * example, if the input is {1, 2, 3, 4}, then the mean is 2.5. * * Hint: the input values are integers, but the output most likely * won't be. Do you need to account for that somehow? */ public static double mean(int[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** The input of this method includes two arrays, which you may assume * are the same size, and whose entries correspond to one another * (for example, the first array may be a list of ages of several people, * while the second array may be a list of the heights of the same people). * The method will compute the average of values from the second array, * but only when the values correspond to entries from the first list * within the range [a, b). For example, if the first array is a list * of ages, {19, 15, 20, 25, 30, 5, 32}, the second array is a list * of heights in feet, {5.2, 4.9, 5.9, 6.1, 5.85, 3.2, 5.7}, and the * range is a=20, b=30, then it would give the average of people aged * 20-29, which in this example would be 6.0. */ public static double meanInRange(int a, int b, int[] list, double[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** When performing data analysis, it is often necessary to first clean * obvious outliers from the data set, because these may be the result * of a clerical error and could throw off analysis. As an example, * when studying medical data, sometimes you will see "zombies" (people * with hospital visits occurring after their recorded date of death) or * "vampires" (people who are hundreds of years old, because their date * of birth was left blank and defaulted to zero when entered into the * the system). This method will eliminate entries from the array of * input values which are outside of the range [a, b), and return the list * of entries which remain. For example, for the input a=0, b=125, and * {10, -1, 20, 30, 25, 125, 40, 200}, the array which is returned would * be {10, 20, 30, 25, 40}. * * Hint 1: you don't need to delete elements from the input array. You * can create a whole new array to return instead. * Hint 2: it may help to know how big your output array is before you * begin. Would any of the other methods you've written help here? */ public static int[] cleanList(int a, int b, int[] list) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** Return the value of the nearest neighbor to v. If v is some value, * look through the list of values to find the one which is closest * in value to v. For example, if v=1.2 and the input array is * {3.2, 1.7, 2.4, 0.9, 4.4}, then the method will return 0.9 because * it is the value closest to 1.2 in the list. If there is a tie (for * example, both 0.9 and 1.5 are the same distance to 1.2), then return * the one which occurs first in the list. If the list is empty, then * return v. */ public static double nearestNeighbor(double v, double[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } /** HONORS SECTION ONLY * (if you are not in the honors section, you do not need to complete * this part, and it is not worth any points if you do): * * Find and return the k elements which are closest to v in value, in * order of increasing distance from v. For example, if v=1.2, k=3, * and the input array is {3.2, 1.7, 2.4, 0.9, 4.4}, then the method * will return {0.9, 1.7, 2.4}. If k is larger than the length of * the input array, then the output array should only have as many values * as you have in the original array. As with nearestNeighbor, if two elements * are the same distance from v, then the one which appears earlier in the * original should be considerd closer in the output array. */ public static double[] kNearestNeighbors(int k, double v, double[] values) { // DELETE THE LINE BELOW ONCE YOU IMPLEMENT THE CALL! throw new RuntimeException("not implemented!"); } }