Question: Java program question ing Exercise 12.14. Write a program that prompts or the This problem is based on Programming name of a text file. The

Java program question

Java program question ing Exercise 12.14. Write a program that prompts or

ing Exercise 12.14. Write a program that prompts or the This problem is based on Programming name of a text file. The file should consist of a sequence of integers, one integer per line. The progranm will read in each line (using nextLine0), parse it as an int (using Integer.parselnt0), and report the number of values and their average. The average should be computed as a double the user f Your program should do some basic exception handling (1) If the file cannot be found then the program should print a message to that effect and terminate by executing System.exit(1). (2) If the file can be found then every time that the program reads in a line that cannot be parsed (i.e Integer.parselnt0 throws a NumberFormatException) the program should print an error message with the bad line. The final printout should display the number of good (i.e. parsable) lines, the average of the parsable values as a double, and the number of bad (unparsable) lines. Two sample runs are shown below: Enter name of input file: numbers.txt Cannot parse eight as an integer. Cannot parse seven as an integer. Cannot parse eighty-five thousand and sixty-two as an integer Cannot parse 13 98 as an integer Number of parsable lines: 6 Average value: 80.83333333333333 Number of unparsable lines 4 Enter name of input file: Nums.txt Could not find file: Nums.txt The values in numbers.txt were as follows: 15 312 16 eight seven eighty-five thousand and sixty-two 13 98 93

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!