Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class StatsDemo public static void main(Stringl] args) double sum0; // The sum of the numbers int count 0; // The number of

image text in transcribed

image text in transcribed

import java.util.Scanner; public class StatsDemo public static void main(Stringl] args) double sum0; // The sum of the numbers int count 0; // The number of numbers added double mean-0; // The average of the numbers double stdDev-; // The standard deviation String line; II To hold a line from the file double difference; II The value and mean difference //Create an object of type Scanner Scanner keyboard-new Scanner(System.in); String filename; // The user input file name //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: ""); filename-keyboard.nextLine (); //Filebriter object //Print the results to the output file //close the output file 1. Download Numbers.txt. 2. Copy StatsDemo.java attached 3. First you need to write output to a file a. Create a FileWriter object passing it the filename Results.txt (Don't forget the needed import statement). b. Create a PrintWriter object passing it the FileWriter object. c. Since you are using a FileWriter object, add a throws clause to the main method header. d. Print the mean and standard deviation to the output file using a three decimal format, labeling each e. Close the output file 4. Compile, debug, and run Now you need to add lines to allow reading from the input file and calculate the mean 1. Create a FileReader object passing it the filename 2. Create a BufferedReader object passing it the FileReader object. 5. Read the file from the first line to the last. 6. The body of the loop will a. convert the line into a double value and add the value to the accumulator b. increment the counter C. read a new line from the file 7. When the program exits the loop close the input file 8. Calculate and store the mean. The mean is calculated by dividing the accumulator by the counter 9. You should now get a mean of 77.444 You need to submit the java file Make sure to include comments Numbers.txt StatsDemo.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago