This is The assignment:
You may start with the code from last week’s program. Your program will
1. Display your name, as usual, in a GUI window.
2. Use Chooser to allow the user to select a file.
3. Open the file, and read all the lines in the file, counting them.
4. Then your program will close the input file.
5. Now allocate an array of double large enough to store one double for each line you read.
6. Your program should then open the input file again. Assume that each line of the file contains a number in a format that Double.parseDouble can handle. Use Double.parseDouble to convert each line of the file into a number, and store those numbers into the array you declared.
7. Pass the array into a method named calculateMean, which will return the mean (regular old average – the sum divided by the number) .
8. Pass the array into a method named calculateStandardDeviation, which will return the sample standard deviation.
9. Pass the array into a method named calculateMaximum, which will return the maximum value in the array.
10. Pass the array into a method named calculateMinimum, which will return the minimum value in the array.
11. Display the mean, standard deviation, maximum, and minimum using a GUI window.
And This is my Code so far:
import java.io.*;
import javax.swing.JFileChooser;
import java.util.Scanner;
import javax.swing.JFrame;
public class random extends JFrame {
public static void main(String[] args) throws IOException
{
System.out.println("My name is Akrm Almsaodi");
JFileChooser jfc = new JFileChooser();
int result = jfc.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION)
{
File file = jfc.getSelectedFile();
Scanner fileScan = new Scanner (file);
FileReader fr = new FileReader(file);
LineNumberReader ln = new LineNumberReader(fr);
int count = 0;
while (ln.readLine() != null){
count++;
}
fileScan.close();
fileScan = new Scanner (file);
final int lines = count;
int [] grad = new int [lines];
long sum=0;
for (int index = 0; index < count ; index++)
{ if (fileScan.hasNext())
{
int num = fileScan.nextInt();
grad[index] = num;
sum += grad[index];
}
}
Array(grad);
public static void Array(int[] x){
int toReturn = 0;
System.out.println(sum/x.length);
//System.out.println("sum = "+sum);
//System.out.println("avg = "+(double) sum/(double) grad.length);
}
}
}
I have to problems: 1- I don't have any idea how I can "Use Double.parseDouble to convert each line of the file into a number, and store those numbers into the array you declared."
2- How can I pass the array into a method named?
I read my textbook and I did a lot of "google searchs" but I couldn't find what I'm looking for, and this is my fifth week with Java :blink:
Please Help!
This post has been edited by x.samo: 05 February 2010 - 02:14 AM

New Topic/Question
Reply




MultiQuote





|