Java Program asking for statistics?
I have to write a java program that asks the user to
# prompt for a file name
# read a set of doubles from the file
# calculate and report n, the mean, and the population standard deviation. Format the mean and standard deviation to two decimal places.
*
Results for Numbers.txt from the sample programs
The sum of the 5 numbers in Numbers.txt is 41.40
average is 8.28
standard deviation 3.09
* Basic outline for the program
// prompt for input file
//while (data remains) {
// input number
// increment n
// accumulate sum of number
// accumulate sumsquares: sum of number^2
// }
// calculate and display n, mean, standard deviation
To calculate the standard deviation use:
sqrt{N sum x^2 -(sum x)^2 over N ^2}
Note: use Math.sqrt() to calculate the square root.
ill be needing to use:
JOptionPane.showInputDialog
How is the file going to be formatted?
String input = JOptionPane.showInputDialog("Enter file name:");
BufferedReader br = new BufferedReader(new FileReader(input));
//this section will differ based on file format
double n = 0;
double sum = 0;
String line = br.readLine();
while(br != null){
//Parse the line of text to get the integers. (also depends on file
//format) If there are multiple integers on a line you'll probably
//want to use an inner loop.
n++;
sum += (the integer)
line = br.readLine();
}
System.out.println("The sum of " + n + " Integers is "+sum);
System.out.println("The Average is "+sum/n);
...
P.S. You should really do your own homework if you want to learn anything.
Journalism Jobs : How to Become a Radio Disc Jockey
sample format of report writing
sample format of report writing
sample format of report writing
No comments:
Post a Comment