2. Task (reuse of code at work!): Rewrite the previous program and make it work when...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
How do sociological theories of deviance and social control elucidate the construction of criminality, the enforcement of laws, and the stigmatization of marginalized groups within society ?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
i) Starbucks launched its prepaid (debit) Starbucks Card in November 2001. The card, which holds between $5 and $500 can be used at any Starbucks location. Suppose Starbucks management wants to study...
-
Discuss how characteristics of not-for-profit organizations and public sector organizations are similar and how they differ.
-
As the supervisor you have to make a decision on disciplinary action. An employee has broken a rule again, after being told not to do so. The employee did not have a good reason for breaking the rule...
-
How to prepare exhibits for trial?
-
Drab Corporation just obtained exclusive rights to a new revolutionary fertilizer that is sure to be an instant success in the gardening industry. Unfortunately, Drab does not control the capital to...
-
(39) Compute the standard deviation (or dispersion) , in the scalar velocities around the mean for neon atoms at 298K. (Molar mass of Ne: 20.2 g/mol.) (40) Obtain the expression for <16>1/3 within...
-
Anchovy acquired 90 percent of Yelton on January 1, 2009. Of Yeltons total acquisition-date fair value, $60,000 was allocated to undervalued equipment (with a 10-year life) and $80,000 was attributed...
-
Differentiate between anaerobic respiration and fermentation in terms of electron acceptors and ATP yield, and discuss how these processes are utilized by different organisms under varying...
-
Show that the ODE x + xe2t sin x + 10 in R with x(0) = 0 has a unique solution. 6. PROBLEM 6 Solve the ODE, for x = x(t), x + x = ex.
-
Compute ending work in process inventory for a manufacturer using the following information. Raw materials purchased Direct materials used Direct labor used Factory overhead Work in process...
-
Maben Company was started on January 1, Year 1, and experienced the following events during its first year of operation: 1. Acquired $30,000 cash from the issue of common stock. 2. Borrowed $40,000...
-
The Wave master 4 0 0 0 T M wave machine creates harmonic water waves that propagate radially outward from the center of a cylindrical pool. Shown above are all the wave crests produced by this...
-
The following data is provided for Garcon Company and Pepper Company for the year ended December 31. Finished goods inventory, beginning Work in process inventory, beginning Raw materials inventory,...
-
Question 19 Choose the correct HTML element to define important text A B) D Question 20 Which of these elements are all elements? (A) B) C (D)
-
Starr Co. had sales revenue of $540,000 in 2014. Other items recorded during the year were: Cost of goods sold ..................................................... $330,000 Salaries and wages...
-
John Fuji (age 37) moved from California to Washington in December 2011. He lives at 468 Cameo Street, Yakima, WA 98901. John's Social Security number is 571-78-5974 and he is single. His earnings...
-
Brian and Kim have a 12-year-old child, Stan. For 2012, Brian and Kim have taxable income of $52,000, and Stan has nonqualifying dividend income of $4,500 and investment expenses of $250. No election...
-
Joan is a self-employed attorney in New York City. Joan took a trip to San Diego, CA, primarily for business, to consult with a client and take a short vacation. On the trip, Joan incurred the...
-
What is the postoperative infection rate? a. 0.25% b. 0.025% c. 2.53% d. 25.30%
-
What is the C-section rate for September? a. 0.03% b. 0.31% c. 3.17% d. 31.69%
-
What is the percentage of multiple births? a. 0.14% b. 14.00% c. 13.98% d. 1.40%
Study smarter with the SolutionInn App