Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Design a training session to maximize learning. page 296

Answered: 1 week ago

Question

Design a cross-cultural preparation program. page 300

Answered: 1 week ago