Question: import java.util.Scanner; import java.io . * ; import java.io . PrintWriter; / * * This class reads numbers from a file, calculates the mean and
import java.util.Scanner;
import java.io;
import java.ioPrintWriter;
This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file.
public class StatsDemo
public static void mainString args throws IOException
Create an object of type Scanner
Scanner keyboard new Scanner Systemin;
Prompt the user and read in the file name
System.out.printlnThis program calculates
"statistics on a file "containing a series of numbers";
System.out.printEnter the file name: ;
String filename "Results.txt;
filename keyboard.nextLine;
To hold a value from the file
double value ;
The sum of the numbers
double sum ;
The number of numbers added
int count ;
The average of the numbers
double mean ;
The standard deviation
double stdDev ;
The value and mean difference
double difference;
ADD LINES FOR TASK # HERE
Create a Scanner object passing it a File object
with the name of the file.
Loop until you are at the end of the file
Read a double value from the file
Add the value to sum
Increment the counter
After the loop finishes, close the input file
Store the calculated mean in the mean variable
ADD LINES FOR TASK # HERE
Create a Scanner object passing it a File object with the name of the file.
Reinitialize sum to
Reinitialize count to
Loop until you are at the end of the file.
Read a double value from the file.
Subtract the mean from the value.
Add the square of the difference to the sum.
Increment the counter.
After the loop finishes, close the input file.
Store the calculated standard deviation in stdDev.
ADD LINES FOR TASK # HERE
Create a PrintWriter object using "Results.txt
PrintWriter writer new PrintWriterResultstxt;
Print the results to the output file
PrintWriter output new PrintWriterResultstxt;
output.printfThe mean is: f
"The standard deviation is: f
;
Close the output file
output.close;
writerclose;
keyboard.close;
not getting output of mean and standard deviation after compiling and running my java code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
