438,557 Members | 1,164 Online Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

 P: 3 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.. Expand|Select|Wrap|Line Numbers 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);     } } } } } }   Nov 29 '06 #1
4 Replies

 Expert Mod 2.5K+ P: 4,677 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.. What's your question? Nov 29 '06 #2

 P: 3 im not sure how to go about adding vectors in my program Nov 29 '06 #3

 10K+ P: 13,264 im not sure how to go about adding vectors in my program Since you know how to read a file, just create a vector using Expand|Select|Wrap|Line Numbers  Vector myScores = new Vector(); Then write a while loop that reads every score on the file and adds it to the vector using Expand|Select|Wrap|Line Numbers  myScores.add(score);  Nov 30 '06 #4

 P: 3 Thanks for replying, I'll try that Nov 30 '06 #5 