grades.java

来自「此系统可用于对学生成绩进行简单管理」· Java 代码 · 共 73 行

JAVA
73
字号
import javax.swing.JOptionPane;
class Grades {
	
	public static void main (String args[]){			
		
		String moreStudentToCalculate;
		String response;
		moreStudentToCalculate=JOptionPane.showInputDialog
		("Do you want to calculate a student's grade?(YES/NO)");
		moreStudentToCalculate=moreStudentToCalculate.toUpperCase();
		
		while(moreStudentToCalculate.equals("YES")){
		
	    response=whatTypeOfStudent();
	    //student type is valid ,let's caculate now!
	    switch(Integer.parseInt(response)){
	    	//English student
	    	case 1:
	    	      EnglishStudent eStudent=new EnglishStudent();
	    	      eStudent.calculate();
	    	      eStudent.display(); 
	              break;
	    	//Math student
	    	case 2: 
	    	      MathStudent mStudent=new MathStudent();
	    	      mStudent.calculate();
	    	      mStudent.display();
	              break;
	    	//science student
	    	case 3:
                  ScienceStudent sStudent=new ScienceStudent();
                  sStudent.calculate();
                  sStudent.display();
	              break;
	         default:
	              JOptionPane.showMessageDialog
	              (null,response+"-is not a valid student type!");
	              System.exit(0);
	    	} 
	    	moreStudentToCalculate=JOptionPane.showInputDialog
	    	("Do you want to calculate another student's grade?(YES/NO)");
	    	moreStudentToCalculate=moreStudentToCalculate.toUpperCase();
	    }//end of while
	        JOptionPane.showMessageDialog(null,
	        "Thanks for using this Grades Calculating Program!");
	    	System.exit(0);
		}//end of main
		public static String whatTypeOfStudent()
		{
			String response;
		    response=JOptionPane.showInputDialog
		    ("Enter student's type(1=English,2=Math,3=Science)");
		    if(response==null)
		      {
		          JOptionPane.showMessageDialog(null,"You clicked a Cancel button!");
		          System.exit(0);
	          }
		    else 
		    if(response.equals(""))
		      {
		          JOptionPane.showMessageDialog(null,"You must make a choice!");
		          System.exit(0);
	          }
	        else
	        if(Integer.parseInt(response)<1|Integer.parseInt(response)>3)
	          {
	              JOptionPane.showMessageDialog
	    	      (null,response+"-is not a valid student type!");
	    	      System.exit(0);
	          }
	        return response;
		}  
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?