📄 grades4.java
字号:
import javax.swing.JOptionPane;
class Grades4{
public static void main(String[] args){
String response;
String moreGrades;
moreGrades = JOptionPane.showInputDialog("Do you want to calculate a grade(Y/N)?");
moreGrades = moreGrades.toUpperCase();
while (moreGrades.equals("Y")){
//what type of student are we calculating?
response = whatKindOfStudent();
switch(Integer.parseInt(response)){
case 1:
EnglishStudent eStudent = new EnglishStudent();
eStudent.calculate();
DisplayGrade eDisplay = new DisplayGrade(eStudent.midterm,eStudent.finalExam,eStudent.research,
eStudent.presentation,eStudent.finalNumericGrade,
eStudent.finalLetterGrade);
break;
case 2:
MathStudent mStudent = new MathStudent();
mStudent.calculate();
DisplayGrade mDisplay = new DisplayGrade(mStudent.midterm,mStudent.finalExam,
mStudent.finalNumericGrade,mStudent.finalLetterGrade);
break;
case 3:
ScienceStudent sStudent = new ScienceStudent();
sStudent.calculate();
DisplayGrade sDisplay = new DisplayGrade(sStudent.midterm,sStudent.finalExam,sStudent.research,
sStudent.finalNumericGrade,sStudent.finalLetterGrade);
break;
default:
JOptionPane.showMessageDialog(null,response+"-is not a valid student type!");
System.exit(0);
}
moreGrades = JOptionPane.showInputDialog("Do you want to calculate another one(Y/N)?");
moreGrades = moreGrades.toUpperCase();
}
JOptionPane.showMessageDialog(null,"Thank you for using this Grades Calculate programm!");
System.exit(0);
}
public static String whatKindOfStudent(){
String response;
response = JOptionPane.showInputDialog("Enter student type(1=English;2=Math;3=Science)");
if(response == null)
{
JOptionPane.showMessageDialog(null,"You have clicked the cancle button!");
System.exit(0);
}
else
if(response.equals(""))
{
JOptionPane.showMessageDialog(null,"You must make a choice in the input box!");
System.exit(0);
}
else
if(Integer.parseInt(response)<1 | Integer.parseInt(response)>3 )
{
JOptionPane.showMessageDialog(null,response+"-is not a valid entry!");
System.exit(0);
}
return response;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -