这是我的方法。对于iOption ==2
, 它说iScore1
iScore2
并iScore3
没有被初始化,即使它们是通过iOption == 1.
程序必须首先使用 iOption 1 在使用 iOption2 之前
while (iOption != '6')
{
if(iOption == 1)
{
iScore1 = Utility.testScore();
iScore2 = Utility.testScore();
iScore3 = Utility.testScore();
Utility.pressEnterToContinue();
Utility.clearScreen();
iOption = Utility.menuOption();
}
if(iOption == 2)
{
System.out.println("\n\tScore 1: " + iScore1);
System.out.println("\n\tScore 2: " + iScore2);
System.out.println("\n\tScore 3: " + iScore3);
System.out.println("\n");
Utility.pressEnterToContinue();
Utility.clearScreen();
iOption = Utility.menuOption();
}
if(iOption == 3)
{
dGrade = Utility.calcAverage(iScore1, iScore2, iScore3);
System.out.println("Average: " + dGrade);
System.out.println("\n");
Utility.pressEnterToContinue();
Utility.clearScreen();
iOption = Utility.menuOption();
}
if(iOption == 4)
{
cLetter2 = Utility.letterGrade(dGrade);
System.out.print("Letter grade: " + cLetter2);
System.out.println("\n");
Utility.pressEnterToContinue();
Utility.clearScreen();
iOption = Utility.menuOption();
}
if(iOption == 5)
{
Utility.calcGPA();
Utility.pressEnterToContinue();
Utility.clearScreen();
iOption = Utility.menuOption();
}
}