Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA - PLEASE READ ALL INSTRUCTIONS The file numbers.text contains data in the following format: header 1 int 1 int 2 header 2 int 1

JAVA - PLEASE READ ALL INSTRUCTIONS

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.

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 optput 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.

Here are the possible problems:

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions