hi,I am working on a program that reads data from a text file into a vector and computes the average score, and highest, lowest score...here is what I have started..
Code:
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class ProcessScoresV1{
public static void main(String[] args)throws FileNotFoundException {
Scanner infile = new Scanner(new FileReader("scores.txt"));
int count = 0;
while (infile.hasNext()) {
String word = infile.next();
count++;
}
final long SENTINEL = -999;
double averageTotal = 0.0;
double averageLow = 0.0;
double averageHigh =0.0;
while (infile.hasNext()) {
double scoreTotal = 0;
long scoreCount = 0;
double score;
while (infile.hasNextDouble()) {
score = infile.nextDouble();
scoreTotal += score;
scoreCount++;
double average = scoreTotal/scoreCount; // computes average of all scores
averageTotal += average;
//high score variables
double scorehigh;
long scoreCounthigh = 0;
double scoreTotalhigh = 0;
// low score variables
double scorelow;
long scoreCountlw = 0;
double scoreTotallw = 0;
if (score < 70) { //condition statement to compute low scores
scorelow = infile.nextDouble();
scoreTotallw += scorelow;
scoreCountlw++;
double averageL = scoreTotallw/scoreCountlw; // computes averages of low scores
averageLow += averageL;
if (score > 70) { //condition statement to compute high scores
scorehigh = infile.nextDouble();
scoreTotalhigh+= scorehigh;
scoreCounthigh++;
double averageH = scoreTotalhigh/scoreCounthigh; // computes averages of high scores
averageH += averageHigh;
JOptionPane.showMessageDialog(null, "Score Total" + scoreTotal + "Total Average Score" + average);
JOptionPane.showMessageDialog(null, "High scores" + scoreTotalhigh + "Average High Scores" + averageH);
JOptionPane.showMessageDialog(null, "Low scores" + scoreTotallw + "Average Low Scores" + averageL);
JOptionPane.showMessageDialog(null, "Number of Total Scores" + count);
}
}
}
}
}
}
Comment