Question
ProcessFile.java is as follows: import java.util.Scanner; import java.io.*; public class ProcessFile { /** * Calculates and prints the max, min, sum count, and average of
ProcessFile.java is as follows:
import java.util.Scanner; import java.io.*;
public class ProcessFile {
/** * Calculates and prints the max, min, sum count, and average of all * integers in a file that is specified as a command line argument. * * @param args args[0] is the filename of the file to process */ public static void main(String[] args) throws FileNotFoundException { if (args.length != 1) { System.out.println("Usage: java ProcessFile filename"); System.exit(1); } //get filename from the args array and create a Scanner for it // need to declare (and initialize) variables // int variables: max, min, sum, count // double variable: average
// process file // only want to examine the integers in the file System.out.println("Maximum = " + max); System.out.println("Minimum = " + min); System.out.println("Sum = " + sum); System.out.println("Count = " + count); System.out.println("Average = " + average); }
}
Given file is as follows:
4 2 Is 18 it time to 15 leave 31.6 yet?? -27.0
If Chegg messes up the formatting and spacing matters, that is:
a blank first line
three(3) spaces btwn. "4" & "2" and "2" & "Is"
four(4) spaces btwn. "Is" & "18" and "18" & "it"
two(2) spaces before "time"
three(3) spaces btwn. "time" & "to"
six(6) spaces btwn. "to" & "15"
two(2) spaces btwn. "15" & "leave"
six(6) spaces btwn. "leave" & "31.6"
five(5) spaces before "yet??"
and finally, 14 spaces before "-27.0"
3. (40 points) Finish the given ProcessFile.java program that receives a filename as a command line argument and prints a usage message and exits if the CLA is missing. You will process through the file skipping any text and non-integer numbers. You can assume that the file has at least one integer. You will print the max, min, sum, count, and average of the integers in the file. HINT: Use hasNextInt() method with an if statement within a while loop. You may want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of your min and max values or use an if/else statement within the loop to reset initial min/max values (if count == 0). If you use the given file as the input file to your program, 31.6 4 2 Is 18 it time to 15 leave yet?? -27.0 your program output should be: Maximum = 18 Minimum = 2 Sum = 39 Count = 4 Average = 9.75 You may want to create additional input files to further test your program. Add the @throws tag to the method javadoc, and add your name to the @author tagStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started