0

java メソッドの統計ですが、56 行目の while ステートメントでメソッドを適切に呼び出すことができないようです。私が間違っていることはありますか?私はJavaに非常に慣れていないので、どんな種類の助けもいただければ幸いです! 前もって感謝します!これが私のコードです:

import java.util.*;
import javax.swing.*;
import java.io.*;

public class GradeCalculator { 
    static String fileInput;
    static double totalGrade;
    static int scoreCount= 0;
    static double classAverage;
    static double score;
    static double testScore;
    static double averageScore;
    static int numberOfStudents = 0;
    static char letterGrade;
    static String fileOutput;
    static String nameOfStudent;
    static int numberCount;
    static int numberCalculatedStudents;
    static double average = 0;

    public static void main (String[] args) throws FileNotFoundException {
    //Welcome   

    JOptionPane.showMessageDialog(null,"Welcome to the Grade Calculator!  This program will\n" +
                                                " calculate the average percentage of 5 test scores that\n"+
                                                " are given in a given file once these scores are\n"+
                                                " averaged it will give the student a letter grade.","Welcome!",JOptionPane.PLAIN_MESSAGE);
    fileInput = JOptionPane.showInputDialog(null, "Please enter the name of the input file you wish to use for this program."
                                            ,"Input File",JOptionPane.PLAIN_MESSAGE);
    fileOutput = JOptionPane.showInputDialog(null, "Please enter the name of the output file you wish to use for this program."
                                            ,"Output File",JOptionPane.PLAIN_MESSAGE);
    //preparing text files
    PrintWriter outFile = new PrintWriter (fileOutput);                                         
    File inFile = new File (fileInput);

    Scanner reader = new Scanner(new FileReader(fileInput));
    outFile.println("Student Name   Test1   Test2   Test3   Test4   Test5   Average Grade");

    while(reader.hasNextLine()) {
        nameOfStudent = reader.next();
        outFile.printf("%n%n%s",nameOfStudent);
        numberOfStudents++;
        score = reader.nextDouble();
        calculateAverage(score);
        calculateGrade(averageScore);
        outFile.printf("                                %.2f   ", averageScore);
        outFile.println("                                                               "+letterGrade);
    }
    classAverage = classAverage/numberCalculatedStudents;       
    outFile.print("\n\n\n\n\n\n\n\n\n\n\n\nClass average for "+ numberCalculatedStudents + "of" + numberOfStudents + "is" + classAverage);
    JOptionPane.showMessageDialog(null,"The report has successfully been completed and written into the file of " + fileOutput +"."
                                                    +" The class average is " + classAverage + ". Please go to the output file for the complete report.");  
    outFile.close();
    }

    public static void calculateAverage(double score) throws FileNotFoundException {
        Scanner reader = new Scanner(new FileReader(fileInput));
        PrintWriter outFile = new PrintWriter (fileOutput);
        while (reader.hasNextDouble() && numberCount <= 5 ) {
            score = reader.nextDouble();
            numberCount++;
        if (score >= 0 & score <= 100) {
                outFile.printf("%10.2f",score);
            scoreCount++;
            average = score + average;
        }
        else
            outFile.printf("                **%.2f",score);
        }
        if (average!=0){
            numberCalculatedStudents++; 
            average = average/scoreCount;
            averageScore = average;
            classAverage = average + classAverage;
            }

            average = 0;
    }

    public static char calculateGrade (double averageScore) {

        if (averageScore >= 90 && averageScore <= 100)
            letterGrade = 'A';
        else if (averageScore < 90 && averageScore >= 80)
            letterGrade = 'B';
        else if (averageScore < 80 && averageScore >= 70)
            letterGrade = 'C';
        else if (averageScore < 70 && averageScore >= 60)
            letterGrade = 'D';
        else if (averageScore < 60 && averageScore >= 0)
            letterGrade = 'F';  
        else 
            letterGrade =' ';

        return letterGrade;
     }  
}
4

1 に答える 1