Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab builds on the technique presented in Lab 4.1, and uses it to validate structured data in a file. The file numbers.text contains data

This lab builds on the technique presented in Lab 4.1, and uses it to validate structured data in a file.

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. Your program's task is to print out the average of each of these sequences.

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.

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 

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

What is the best conclusion for Xbar Chart? UCL A X B C B A LCL

Answered: 1 week ago

Question

5. Discuss the key roles for training professionals.

Answered: 1 week ago