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
-
Clearly and logically show all work. Name: 3. (20 points) Find the dimensions of the rectangle, with the maximum perimeter, that can be in- scribed, with sides parallel to the coordinate axes, in the...
-
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...
-
What are the potential benefits and risks of using participative leadership?
-
Given the impressive advances made in science over the past 50 years, especially in the area of detecting substances and ingredients, scientists now claim to be able to detect one drop of blood in a...
-
The following summarized data are related to Kennedy Corporation's operations: Required Prepare a multiple-step income statement for Kennedy Corporation. Include earnings per share disclosure at the...
-
Liang Company began operations on January 1, 2014. During its first two years, the company completed a number of transactions involving sales on credit, accounts receivable collections, and bad...
-
Question 5 (Problem 5.15) For the beam and loading shown, determine the maximum normal stress due to bending on a transverse section at C. 3kN 3kN SO mm -15 m 15m--1.5 m 300 mm
-
On January 1, Ruiz Company issued bonds as follows: Face Amount $500,000 15 Number of Years: Stated Interest Rate: Interest payments per year (Note: the bonds pay interest semi-annually.) Required:...
-
A small business created an app that targets people who want to practice their conversational Spanish. When creating the app, the developers decided to create options for beginners, intermediate and...
-
municipal bond has a coupon rate of 6.10 percent and a YTM of 5.71 percent. If an investor has a marginal tax rate of 30 percent, what is the equivalent pretax yield on a taxable bond? 2.Myca...
-
Nina buys a call option on Pandora that has a strike price of $1000 and an expiry in 1 year. The premium she pays for the option is $50. When the option expires the price of Pandora is $1060.00. (All...
-
write three pages on the role of the government in economic growth from WWII until the 1970s. What were the causes of economic growth? What are the benefits of economic growth write a detailed note...
-
Company: ShareCare What is the value proposition? Company: Genomind What is the revenue model? How does it disrupt the healthcare business enviroment? NO PAPER WORK ONLY TYPED ANSWERS ASAP
-
What types of economic policies have been shown to promote social mobility, and which policies tend to exacerbate social stratification ?
-
(a) Explain why the marginal cost curve above the average variables cost curve is referred to as the firms short run supply curve? ( use both verbal and diagram analysis) (6) (b) With a help of a...
-
How can NAFTA be beneficial to suppliers of Walmart?
-
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...
-
Hardwoods, Inc. purchased a tract of timber for a total cost of \($500,000\). The tract is estimated to contain 200,000 board feet of lumber once the timber is harvested. Hardwoods expects the land...
-
Match the descriptive explanation below with the correct term: 1. An exclusive right that protects an owner against the unauthorized reproduction of a specific written work. 2. The periodic write-off...
-
Rollins Co. reported the following information in its 2018 financial statements: Compute the return on assets and asset turnover for Rollins Co. in 2018. Net sales. Net income Beginning of year total...
Study smarter with the SolutionInn App