我不断收到一个编译器错误,指出在代码显示 public static String Mainmenu (menu); 的地方需要一个标识符。我是编程新手,所以我知道这可能很简单。代码使用方法,当所有编译正确时,它应该作为成绩平均程序运行。
import java.util.Scanner;
public class Homework4 {
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
int choice;
String name;
String menu1;
double homeworkAverage = 0.0;
double quizAverage = 0.0;
double testAverage = 0.0;
double average = 0.0;
double totalAverage = 0.0;
do{
menu1 = Mainmenu;
choice = input.nextInt();
if( choice == 1 )
{
System.out.println( "Eneter the student's name:");
name = input.next();
System.out.println( "Enter homework grades");
homeworkAverage = mean();
System.out.println( "Enter Quiz Grades");
quizAverage = mean();
System.out.println( "Enter Test Grades");
testAverage = mean();
totalAverage = 0.25*homeworkAverage + 0.25*quizAverage +0.5*testAverage;
System.out.println( "The average for " + name + " is: " + totalAverage );
}
else if ( choice == 2 )
{
System.out.println( "Now quiting...");
}
else
{
System.out.println( "Invalid Choice" );
}
}while( choice != 2 );
}
public static String Mainmenu ( menu );
{
Scanner input = new Scanner( System.in );
String menu;
System.out.println("Welcome to Grader 1.0");
System.out.println("1. Average a New Student");
System.out.println("2. Quit");
System.out.println("Please Enter Your Choice:");
return menu;
}
public static double mean(double average );
{
Scanner input = new Scanner( System.in );
double grade = 0.0;
double average = 0.0;
double gradeTotal = 0.0;
int numberOfGrades = 0;
while( grade != -1 )
{
System.out.println( "Please enter the next grade or -1 when finished: ");
grade = input.nextDouble ();
if( grade != -1 )
{
gradeTotal = gradeTotal + grade;
numberOfGrades++;
}
}
if( numberOfGrades > 0 )
{
average = gradeTotal / numberOfGrades;
}
else
{
System.out.println("No grades, no average");
}
return average;
}
}