Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!