Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA - PLEASE READ ALL INSTRUCTIONS. Thank you so very much. KEY - Please write a prohram that THROWS and CATCHES EXCEPTIONS if any of

JAVA - PLEASE READ ALL INSTRUCTIONS. Thank you so very much.

KEY - Please write a prohram that THROWS and CATCHES EXCEPTIONS if any of the below situations, PROBLEMS, are detected.

EACH of the below situations, PROBLEMS, must be detected.

If present, an exception:

1.) MUST BE be thrown,

2.) no average is calculated, and

3.) processing proceeds to the next sequence.

PLEASE WRITE A PROGRAM to print out, to the screen, the average of each of these sequences.

The output must take in the below considerations AND the oUtput must look like below's example.

However, the file contents is often corrupted by the time it gets to your program, so the data must be validated.

The file numbers.text contains data in the following format:

header1 int1 int2  header2 int1 int2  i.e., each line begins with a header value, followed by that number of integers. 

PROBLEMS/SITUATIONS - Throws exceptions mut be written for:

A header value of 0

A negative header value

An empty line

Fewer values than specified by the header

More values than specified by the header

Each of these situations must be detected and if present, an exception should be thrown, no average is calculated, and processing proceeds to the next sequence.

The name of your class should be DataChecker.

INPUT DATA: (from text file)

For example, if the file numbers.text contains:

3 1 2 3 0 1 12 -12 14 1 2 3 5 1 2 3 4 5 6 4 10 20 30 40 

PROGRAM'S OUTPUT:

the program should produce the following output:

The average of the values on line 1 is 2.0 *** Error (line 2): Line is empty - average can't be taken *** Error (line 3): Header value of 0 - average can't be taken The average of the values on line 4 is 12.0 *** Error (line 5): Corrupt line - negative header value *** Error (line 6): Corrupt line - fewer values than header *** Error (line 7): Corrupt line - extra values on line The average of the values on line 8 is 25.0 There were 3 valid lines of data There were 5 corrupt lines of data 

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

Step: 3

blur-text-image

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

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions