Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Write a method that takes two file name strings as parameters, inputFileName and outputFileName , analyzes the sequence of integers stored in the first

Java

Write a method that takes two file name strings as parameters, inputFileName and outputFileName , analyzes the sequence of integers stored in the first file and stores results of analysis in the second file. The following statistics of the data in inputFileName must be calculated and written into the outputFileName file:

  • the number of integers stored,
  • the largest and the smallest number stored in file,
  • the total of all numbers stored in the file.

Assume that all the numbers stored in the input file are integers and stored one number per line.

The method does not return any values.

The method throws IOException when the files fail to open for reading and writing. Instead of catching the exception in the method let it bubble up into the calling code. Please see an example of how it is done in buildTestFile( ) and areEqualFiles( ) methods in TwoMethodsA04.zip

Requirements:

  • Do not store numbers in array or ArrayList. Process one number at a time and proceed to the next one.
  • All statistics must be collected with just one pass through the file.
  • Add Java Doc comments before the method header. See how to write them here: https://www.oracle.com/technetwork/java/javase/tech/index-137868.html (Links to an external site.)

Following are some examples

Example # 1: File "testCaseIN.txt" has the following numbers in it:

33 -1 0 2

The output file will have the following statistics written into it

Numeric Data File "testCaseIN.txt" Analysis Number of integers: 4 The sum of all integers in file: 34 The largest integer in the set: 33 The smallest integer in the set: -1

Example # 2: File "testCaseIn1.txt" has only one number: 1

1

The output file will have the following statistics written into it

Numeric data file "testCaseIn1.txt" has only one number: 1

Example # 3: File "testCaseIn2.txt" is empty

The output file will have the following statistics written into it

Numeric data file "testCaseIn2.txt" is empty 

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions