你好 stackoverflow 社区。目前我是java新手,我正在尝试弄清楚如何模块化程序。无论出于何种原因,当我返回变量 averageScore 时,它都会在 main 方法中给我该变量的错误。任何帮助,将不胜感激。
public class Program4
{
public static void main(String[ ] args)
{
EasyReader console = new EasyReader(); //Connect to EasyReader.class
System.out.print("Enter the score from game 1: ");
double score1 = console.readDouble(); //Reads the user input for game 1
System.out.print("Enter the score from game 2: ");
double score2 = console.readDouble(); //Reads the user input for game 2
System.out.print("Enter the score from game 3: ");
double score3 = console.readDouble(); //Reads the user input for game 3
average(score1, score2, score3);
displayScores(score1, score2, score3, averageScore);
}
public static void average(double score1, double score2, double score3)
{
double averageScore = ((double)score1+score2+score3)/3; //Divides miles by gallons
getAverage();
}
public static double getAverage()
{
return new averageScore;
}
public static void displayScores(double score1, double score2, double score3, double averageScore)
{
System.out.println("Game 1 Score: " + score1 + " points"); //Prints score 1
System.out.println("Game 2 Score: " + score2 + " points"); //Prints score 2
System.out.println("Game 3 Score: " + score3 + " points"); //Prints score 3
System.out.println("Average score: " + RoundDouble.roundDouble(averageScore, 2) + " points "); //Prints the average score and rounds it to 2 decimals
}
}