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.io.PrintWriter;
/**
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 main(String[] args) throws IOException {
// Create an object of type Scanner
Scanner keyboard = new Scanner (System.in);
// Prompt the user and read in the file name
System.out.println("This program calculates "+
"statistics on a file "+ "containing a series of numbers");
System.out.print("Enter the file name: ");
String filename = "Results.txt";
filename = keyboard.nextLine();
// To hold a value from the file
double value =0;
// The sum of the numbers
double sum =0;
// The number of numbers added
int count =0;
// The average of the numbers
double mean =0;
// The standard deviation
double stdDev =0;
// The value and mean difference
double difference;
// ADD LINES FOR TASK #4 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 #5 HERE
//Create a Scanner object passing it a File object with the name of the file.
//Reinitialize sum to 0.
//Reinitialize count to 0.
//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 #3 HERE
//Create a PrintWriter object using "Results.txt"
//PrintWriter writer = new PrintWriter("Results.txt");
//Print the results to the output file
PrintWriter output = new PrintWriter("Results.txt");
output.printf("The mean is: %.3f
"+ "The standard deviation is: %.3f
",0.000,0.000);
//Close the output file
output.close();
//writer.close();
keyboard.close();
}
} not getting output of mean =0.000 and standard deviation =0.000 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 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!