Question: File Analysis Method ( Name this project FileAnalysisMethod.java) Write method int fileAnalysis( String inputFileName, String outputFileName ) that analyzes the sequence of integers stored in
File Analysis Method (Name this project FileAnalysisMethod.java) Write method int fileAnalysis(String inputFileName, String outputFileName) that analyzes the sequence of integers stored in a file with a given name (inputFileName), and calculates the following statistics about the data stored in file: the number of integers stored, the largest and the smallest number stored in file, the total of all numbers stored in the file.
All that statistics must be stored in another file. The name of that output file is provided in parameter outputFileName. The method returns the number of the integers processed. Assume that all the numbers stored in the input file are integers and stored one number per line. The method throws IOException when the files fail to open for reading and writing. If the input file does not exist, the method returns 0. Sample statistics output file format is the following: Numeric data file name: nums.txt Number of integers: 5 The total of all integers in file: 15 The largest integer in the set: 5 The smallest integer in the set: 1
Test new method in main(). Make sure to use try/catch block to handle IOExceptions it may throw. Do not use user input for testing, create test cases that are easy to follow when reading your code. Suggested testing strategy: create a small testing text file containing 3 5 numbers that are easy to add up and where smallest and largest numbers are obvious. Make sure your method runs well with this data set. Do not use user input in your test cases. Sample file contents: 5 3 1 4 2
Requirements: 1. DO NOT use arrays or ArrayLists to store the numbers in the integer set. Numbers must be analyzed on the spot. Review how the algorithm (from Asg. 3) to find the smallest and the largest number in the set. Never assume that all the numbers in the set are positive. 2. For the analysis go through the set of numbers in the file ONCE. 3. main() cannot throw any exceptions. Please handle exceptions in main() properly.
The greatest of a set of numbers algorithm: 1. Get (input) the first number, set it to be the greatest for now. 2. Get the next number. 3. If the new number is bigger than the greatest one set the new one to be the greatest. 4. Repeat steps 2 - 4 until all the numbers are consumed.
******************************Fore reveiw of previous Asg. 3*************************************************
public class GreatestAndLeast { public static void main(String[] args) { int max = 0; int min = 0; int input; int num = 0; int first; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter positive number. Enter -99 to quit: "); first = keyboard.nextInt(); if (first <0) { System.out.println("no numbers were entered!"); System.out.println("Please enter positive number. Enter -99 to quit: "); } input = keyboard.nextInt(); while (input !=-99) { num = keyboard.nextInt(); if (input > num) { max = input; min = num; } if (num ==-99) { System.out.println("Greatest: " + max); System.out.println("Least: " + min); System.exit(0); } } } }
***************************************************************************
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
