Question
Solve it by JAVA please. Method 6: public static int numInRange(int a, int b, int[] values) Determines the number of elements from the array of
Solve it by JAVA please.
Method 6: public static int numInRange(int a, int b, int[] values)
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).
Method 7: public static double mean(int[] values)
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?
Method 8: public static double meanInRange(int a, int b, int[] list, double[] values)
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. The ages 20 and 25 in this example are in range, giving the mean (5.9 + 6.1)/2 = 6.0.
Method 9: public static int[] cleanList(int a, int b, int[] list)
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?
Method 10: public static double nearestNeighbor(double v, double[] values)
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.
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