Question: 2. Task (reuse of code at work!): Rewrite the previous program and make it work when the list is populated with values found in



2. Task (reuse of code at work!): Rewrite the previous program and make it work when the list is populated with values found in an input file. The name of the file should be input from the user. Handle all possible cases (use try/catch statements). Have a constant for max size and read at most these many values from the file. Your output should be similar to the following samples: SAMPLE OUTPUT #1: Please input the name of the file to be opened: input.tx File Not Found! Exit program! SAMPLE OUTPUT #2: For this file holding all values of unwanted types: a nd fdsvfd sdfgvdf 3.5 3.23 sdafs asdasf erqwewr f Please input the name of the file to be opened: input.txt The file doesn't contain any integers. Exit program! SAMPLE OUTPUT # 3: For this file holding mixed types: 34 a 55 18 47 89 b 88 37 20 27 10 78 39 21 n m ghff Please input the name of the file to be opened: input2.txt The list size is: 16 The list is: 34 55 18 47 89 45 67 59 88 37 20 27 10 78 39 21 Your options are: 1) All even values? 2) All unique values? 3) Print min gap between values 4) Statistics 5) Print 80% percentile 0) EXIT Please enter your option: 3 The minimum gap between 2 adjacent values is -5: Your options are: 1) All even values? 2) All unique values? 3) Print min gap between values 4) Statistics 5) Print 80% percentile 0) EXIT Please enter your option: 2 All values/list are unique values. Your options are: 1) All even values? 2) All unique values? 3) Print min gap between values 4) Statistics 5) Print 80% percentile 0) EXIT Please enter your option: 1 Some values/list are odd. Your options are: 1) All even values? 2) All unique values? 3) Print min gap between values 4) Statistics 5) Print 80% percentile 0) EXIT Please enter your option: m Not an integer! Try again! Please enter your option: 5 The list sorted: 10 18 20 21 27 34 37 39 45 47 55 59 67 78 88 89 80%-percentile from this list: 89 88 78 Your options are: 1) All even values? 2) All unique values? 3) Print min gap between values 4) Statistics 5) Print 80% percentile 45 67 59 abbbb (0) EXIT Please enter your option: wer Not an integer! Try again! Please enter your option: 4 Statistics for this list: 34 55 18 47 89 45 67 59 The mean for this list is: 45.88 The variance for this list is: 584.11 The standard deviation for this list is: 24.17 Your options are: 1) All even values? 2) All unique values? 3) Print min gap between values 4) Statistics 5) Print 80% percentile (0) EXIT Please enter your option: 0 Testing completed. 88 37 20 27 10 78 39 21 1. Task: Write a Java program using the following methods for a 1-dim array (list): A method named get Int to get input a valid integer. The method is used to test for type errors in input. A method named initRand to fill the array with random values: the elements of the array should be random integers between 1 and 100 (declared as class constants). A method named print to print the elements of the array. Use printf. A method named isAllEven that returns a boolean value indicating whether or not all of the values are even numbers. A method named isUnique that returns a boolean value indicating whether or not the values in the array are unique. The values in the list are considered unique if there is no pair of values that are equal. A method named minGap that returns the minimum 'gap' between adjacent values in the array. The gap between two adjacent values in an array is defined as the second value minus the first value. A method named menu that prints a list of options and returns a valid option (check the sample output). A method named bubbleSort that sorts the array in ascending order. A method named copy that makes a copy of a 1-dim array into another 1-dim array. A method named top_20 that prints the values in the 80%-percentile (top 20%). The method should start with sorting a copy of the array and continue with printing the top 20% from this sorted copy. Keep the original array unsorted. A method named get Mean that returns the average value/array. You may have to overload this method for an array of int/double A method named getVariance that returns the variance of a list of integers. Assume the parameter/method is an array named list. You should create a second array holding the squares of the deviations of a value (list[i]) from its mean value. The variance is the mean of this second array. NOTE: The sample output shows also the standard deviation for option 4. The standard deviation is the square root of the variance. No need for a method. All methods should take as input parameters the array and its size. Write a driver program to call these methods and get output similar to the sample output below.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
