我不断得到:
表达式的非法开头,';" 预期 System.exit(0),并在解析时到达文件末尾
这是对它应该做什么和代码的描述。
要解决的问题:
我应该在课外学习多少?
问题:
你的同学需要帮助。这是他们上大学的第一年,他们需要确定需要学习多少小时才能获得好成绩。
Study Hrs Per Week Per Credit Grade
5: A,
4: B,
3: C,
2: D,
0: F,
项目规格:
- 用户可以根据他们输入的学分输入他们计划每周学习的小时数或他们想要的成绩。(注意:您的程序必须为用户提供两个选项。)
- 该程序会显示用户的姓名、学分数、学习总时数以及他们应该期望获得的成绩。
- 您可以使用编程逻辑入门课程中涵盖的任何编程技术来完成这个项目。但是,这需要您提前阅读教科书中有关如何在 Java 编程语言中实现该技术的说明。
下面是我的代码:
import javax.swing.JOptionPane; //Needed for the dialogue box
/**
This program shows the student the grade they will receive
or how much to study for a certain grade.
*/
public class MoultonAlainaProject1
{
public static void main(String[] args)
{
string wantedGrade, desiredGrade, name, input;
char finalGrade;
int gradeA = 5;
int gradeB = 4;
int gradeC = 3;
int gradeD = 2;
int gradeF = 0;
float studyHrs;
int creditHrs, userChoice;
//Scanner for keyboard input
Scanner keyboard = new Scanner(System.in);
name = JOptionPane.showInputDialog("Please enter your name.");
input = JOptionPane.showInputDialog("How many credit hours do you plan on taking this semester?");
creditHrs = integer.parseInt(input);
input = JOption.showInputDialog("If you would like to know the amount of hours you should study for the amount of" +
"credit hours press 1. If you would like to know the grade you would receive by" +
"entering the amount of hours you plan to study press 2.");
userChoice = integer.parseInt(input);
if (userChoice == 1)
{
desiredGrade = JOptionPane.showInputDialog("Enter the grade you would like to receive.");
if (desiredGrade == 'A' || 'a')
{
wantedGrade = gradeA;
}
else
{
if (desiredGrade == 'B' ||'b')
{
wantedGrade = gradeB;
}
else
{
if (desiredGrade == 'C' || 'c')
{
wantedGrade = gradeC;
}
else
{
if (desiredGrade == 'D' || 'd')
{
wantedGrade = gradeD;
}
else
{
if (desiredGrade == 'F' || 'f')
{
wantedGrade = gradeF;
}
else
{
System.out.printIn("Error: you have not entered a valid input.");
}
}
}
}
}
studyHrs = wantedGrade * creditHrs;
}
else
{
if (userChoice == 2)
{
input = JOptionPane.showInputDialog("Enter the amount of hours you plan to study a week.");
studyHrs = integer.parseInt(input);
wantedGrade = studyHrs/creditHrs;
if (wantedGrade >= 5)
{
finalGrade = "A";
}
else
{
if (wantedGrade >= 4)
{
finalGrade = "B";
}
else
{
if (wantedGrade >= 3)
{
finalGrade = "C";
}
else
{
if (wantedGrade >= 2)
{
finalGrade = "D";
}
else
{
if (wantedGrade < 2)
{
finalGrade = "F";
}
}
}
}
}
JOptionPane.showMessageDialog(null, name+ ", you are taking " +creditHrs+ "credit hours, you should study " +studyHrs+ " hours a week to receive " +finalGrade+ " in your classes."
System.exit(0);
}
}
我已经检查了很多次牙套,但我可能在某个地方遗漏了一些东西