java语言额堂测试

package java88;
public class ScoreInformation {
  public ScoreInformation() {};
  private String stunumber="NULL";
  private String name="NULL";
  private double  mathematicsscore=0;
  private double englishscore=0;
  private double networkscore=0;
  private double databasescore=0;
  private double softwarescore=0;
  public void setstunumber(String stunumber) {
	  this.stunumber=stunumber;
  }
  public String getstunumber() {
	  return stunumber;
  }
  public void setname(String name) {
	  this.name=name;
  }
  public String getname() {
	  return name;
  }
  public void setmathematicsscore(double mathematicsscore) {
	  this.mathematicsscore=mathematicsscore;
  }
  public double getmathematicsscore() {
	  return mathematicsscore;
  }
  public void setenglishscore(double englishscore) {
	  this.englishscore=englishscore;
  }
  public double getenglishscore() {
	  return englishscore;
  }
  public void setnetworkscore(double networkscore) {
	  this.networkscore=networkscore;
  }
  public double getnetworkscore() {
	  return networkscore;
  }
  public void setdatabasescore(double databasescore) {
	  this.databasescore=databasescore;
  }
  public double getdatabasescore() {
	  return databasescore;
  }
  public void setsoftwarescore(double softwarescore) {
	  this.softwarescore=softwarescore;
  }
  public double getsoftwarescore() {
	  return softwarescore;
  }
	
};
package java88;
import java.util.*;
import java.text.DecimalFormat;
import java.util.Scanner;
import java88.ScoreInformation;
public class ScoreManagement {
     static Scanner in=new Scanner(System.in);
     static void display() {
    	 System.out.println("***********************************************************");
    	 System.out.println("                石家庄铁道大学软件工程系                                      ");
    	 System.out.println("                学生学籍管理系统 2019 版                                     ");
    	 System.out.println("***********************************************************");
    	 System.out.println("                 1、 学生考试成绩录入                                           ");
    	 System.out.println("                 2、 学生考试成绩修改                                           ");
    	 System.out.println("                 3、 计算学生成绩绩点                                          ");
    	 System.out.println("                 4、退出学籍管理系统                                            ");
    	 System.out.println("***********************************************************");
     }
     static void displayexit() {
    	 System.out.println("***********************************************************");
    	 System.out.println("   谢谢使用石家庄铁道大学软件工程系学生学籍管理系统 2019 版       ");
    	 System.out.println("                    制作人:高帅                                                  ");
    	 System.out.println("***********************************************************");
    	 System.exit(0);
     }
     
     static void displayscorescan() {
    	 System.out.println("***********************************************************");
    	 System.out.println("       石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	 System.out.println("                     学生考试成绩录入                                         ");
    	 System.out.println("***********************************************************");
    	 System.out.println("                请输入学生学号:XXXXXXXX"                    );
    	 System.out.println("***********************************************************");
    	 scorescan();
     }
     static void scorescan() {
    	 
    	 String str=in.next();
    	 int flag=0;
    	 for(int i=0;i<5;i++) {
    		 if(str.equals(stu[i].getstunumber())) {
    	System.out.println("学生信息:"+"姓名:"+stu[i].getname()+","+"学号:"+stu[i].getstunumber()); 
    	displayscorescan2(i);
    	flag=1;
    		 }	 
    	 }
    if(flag==0) {
    	System.out.println("没有此学生!");
    	displayscorescan();
    } 
     }
     static void displayscorescan2(int a) {
    	 System.out.println("***********************************************************");
    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	 System.out.println("                  学生考试成绩录入                                         ");
    	 System.out.println("***********************************************************");
    	 System.out.println("                      学生学号: "+stu[a].getstunumber());
    	 System.out.println("                      学生姓名: "+stu[a].getname());
    	 System.out.println("                  请输入高等数学成绩: ");
    	 stu[a].setmathematicsscore(in.nextDouble());
    	 System.out.println("                  高等数学成绩:"+stu[a].getmathematicsscore());
    	 System.out.println("                  请输入大学英语成绩: ");
    	 stu[a].setenglishscore(in.nextDouble());
    	 System.out.println("                  大学英语成绩:"+stu[a].getenglishscore());
    	 System.out.println("                  请输入计算机网络成绩:                                       ");
    	 stu[a].setnetworkscore(in.nextDouble());
    	 System.out.println("                  计算机网络成绩:"+stu[a].getnetworkscore());
    	 System.out.println("                  请输入数据库成绩:                                       ");
    	 stu[a].setdatabasescore(in.nextDouble());
    	 System.out.println("                  数据库成绩:"+stu[a].getdatabasescore());
    	 System.out.println("                  请输入软件工程成绩:                                       ");
    	 stu[a].setsoftwarescore(in.nextDouble());
    	 
    	 System.out.println("                  软件工程成绩:"+stu[a].getsoftwarescore());
    	 
    	 System.out.println("该学生成绩已录入完毕,是否提交(Y/N)");
    	 String tijiao=in.next();
    	 //System.out.println(tijiao);
    	 if(tijiao.equals("Y")) {
    		 //display();
    	 }
    	 else {
    		 stu[a].setmathematicsscore(0);
    		 stu[a].setenglishscore(0);
    		 stu[a].setnetworkscore(0);
    		 stu[a].setdatabasescore(0);
    		 stu[a].setsoftwarescore(0);
    		 displayscorescan();
    	 }
    	 System.out.println("***********************************************************");
     }
     static void update() {
    	 System.out.println("***********************************************************");
    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	 System.out.println("                  学生考试成绩修改界面                                        ");
    	 System.out.println("***********************************************************");
    	 System.out.println("                    请输入学生学号:                                              ");
    	 System.out.println("***********************************************************");
    	 
    	 String str2=in.next();
    	 int flag2=0;
    	 for(int i=0;i<5;i++) {
    		 if(str2.equals(stu[i].getstunumber())) {
    			 System.out.println("***********************************************************");
    	    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	    	 System.out.println("                  学生考试成绩录入                                         ");
    	    	 System.out.println("***********************************************************");
    	    	 System.out.println("                      学生学号: "+stu[i].getstunumber());
    	    	 System.out.println("                      学生姓名: "+stu[i].getname());
    	    	 System.out.println("                  1、高等数学成绩:"+stu[i].getmathematicsscore());
    	    	 System.out.println("                  2、大学英语成绩:"+stu[i].getenglishscore());
    	    	 System.out.println("                  3、计算机网络成绩:"+stu[i].getnetworkscore());    	    	 
    	    	 System.out.println("                  4、数据库成绩:"+stu[i].getdatabasescore());    	    	 
    	    	 System.out.println("                  5、软件工程成绩:"+stu[i].getsoftwarescore());
    	    	 System.out.println("请输入要修改科目对应的序号:");
    	    	 int b=in.nextInt();
    	    	 System.out.println("***********************************************************");
    	    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	    	 System.out.println("                  学生考试成绩录入                                         ");
    	    	 System.out.println("***********************************************************");
    	    	 System.out.println("                      学生学号: "+stu[i].getstunumber());
    	    	 System.out.println("                      学生姓名: "+stu[i].getname());
    	    	 double memorymath=stu[i].getmathematicsscore();
    	    	 double memoryenglish=stu[i].getenglishscore();
    	    	 double memorynet=stu[i].getnetworkscore();
    	    	 double memorydata=stu[i].getdatabasescore();
    	    	 double memorysoft=stu[i].getsoftwarescore();
    	    	 switch(b) {
    	    	 case 1:System.out.println("请输入修改后的高等数学的成绩:");  	    
    	    	 stu[i].setmathematicsscore(in.nextDouble());	    	 
    	    	 System.out.println("***********************************************************");
    	    	 break;
    	    	 case 2:System.out.println("请输入修改后的大学英语的成绩:");  	    	 
    	    	 stu[i].setenglishscore(in.nextDouble());   	    	 
    	    	 System.out.println("***********************************************************");
    	    	 break;
    	    	 case 3:System.out.println("请输入修改后的计算机网络的成绩:");  	    	 
    	    	 stu[i].setnetworkscore(in.nextDouble()); 	    	 
    	    	 System.out.println("***********************************************************");
    	    	 break;
    	    	 case 4:System.out.println("请输入修改后的数据库的成绩:");  	    	 
    	    	 stu[i].setdatabasescore(in.nextDouble());  	    	 
    	    	 System.out.println("***********************************************************");
    	    	 break;
    	    	 case 5:System.out.println("请输入修改后的软件工程的成绩:");
    	    	 
    	    	 stu[i].setsoftwarescore(in.nextDouble());
    	    	 
    	    	 System.out.println("***********************************************************");
    	    	 break;
    	    	 }
    	    	 System.out.println("***********************************************************");
    	    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	    	 System.out.println("                  学生考试成绩录入                                         ");
    	    	 System.out.println("***********************************************************");
    	    	 System.out.println("                      学生学号: "+stu[i].getstunumber());
    	    	 System.out.println("                      学生姓名: "+stu[i].getname());
    	    	 System.out.println("                  高等数学成绩:"+stu[i].getmathematicsscore());
    	    	 System.out.println("                  大学英语成绩:"+stu[i].getenglishscore());	    
    	    	 System.out.println("                  计算机网络成绩:"+stu[i].getnetworkscore());
    	    	 System.out.println("                  数据库成绩:"+stu[i].getdatabasescore());	         
    	    	 System.out.println("                  软件工程成绩:"+stu[i].getsoftwarescore());
    	    	 System.out.println("            该学生成绩已修改完毕,是否提交(Y/N)   ");
    	    	 String tijiao=in.next();
    	    	 if(tijiao.equals("Y")) {
    	    		 //display();
    	    	 }
    	    	 else {
    	    		 if(b==1)
    	    			 stu[i].setmathematicsscore(memorymath);
    	    		 if(b==2)
    	    			 stu[i].setenglishscore(memoryenglish);
    	    		 if(b==3)
    	    			 stu[i].setnetworkscore(memorynet);
    	    		 if(b==4)
    	    			 stu[i].setdatabasescore(memorydata);
    	    		 if(b==5)
    	    			 stu[i].setsoftwarescore(memorysoft);
    	    		 update();
    	    	 }
    	    	 System.out.println("***********************************************************");
    	    	 flag2=1;
    		 }
    	 }
    	 if(flag2==0) {
    		 System.out.println("该学生不存在!");
    		 update();
    	 }
     }
     static double mathjd(int i) {
    	 double mathjd=0;
    	 if(stu[i].getmathematicsscore()>=90)
    		 mathjd=4.0;
    	 if(stu[i].getmathematicsscore()<=89.9&&stu[i].getmathematicsscore()>85)
    		 mathjd=3.7;
    	 if(stu[i].getmathematicsscore()<=84.9&&stu[i].getmathematicsscore()>82)
    		 mathjd=3.2;
    	 if(stu[i].getmathematicsscore()<=81.9&&stu[i].getmathematicsscore()>78)
    		 mathjd=3.0;
    	 if(stu[i].getmathematicsscore()<=77.9&&stu[i].getmathematicsscore()>75)
    		 mathjd=2.7;
    	 if(stu[i].getmathematicsscore()<=74.9&&stu[i].getmathematicsscore()>72)
    		 mathjd=2.3;
    	 if(stu[i].getmathematicsscore()<=71.9&&stu[i].getmathematicsscore()>68)
    		 mathjd=2.0;
    	 if(stu[i].getmathematicsscore()<=67.9&&stu[i].getmathematicsscore()>66)
    		 mathjd=1.7;
    	 if(stu[i].getmathematicsscore()<=65.9&&stu[i].getmathematicsscore()>64)
    		 mathjd=1.5;
    	 if(stu[i].getmathematicsscore()<=63.9&&stu[i].getmathematicsscore()>=60)
    		 mathjd=1.0;
    	 if(stu[i].getmathematicsscore()<60)
    		 mathjd=0;
    	return mathjd;
     }
     static double englishjd(int i) {
    	 double englishjd=0;
    	 if(stu[i].getenglishscore()>=90)
    		 englishjd=4.0;
    	 if(stu[i].getenglishscore()<=89.9&&stu[i].getenglishscore()>85)
    		 englishjd=3.7;
    	 if(stu[i].getenglishscore()<=84.9&&stu[i].getenglishscore()>82)
    		 englishjd=3.2;
    	 if(stu[i].getenglishscore()<=81.9&&stu[i].getenglishscore()>78)
    		 englishjd=3.0;
    	 if(stu[i].getenglishscore()<=77.9&&stu[i].getenglishscore()>75)
    		 englishjd=2.7;
    	 if(stu[i].getenglishscore()<=74.9&&stu[i].getenglishscore()>72)
    		 englishjd=2.3;
    	 if(stu[i].getenglishscore()<=71.9&&stu[i].getenglishscore()>68)
    		 englishjd=2.0;
    	 if(stu[i].getenglishscore()<=67.9&&stu[i].getenglishscore()>66)
    		 englishjd=1.7;
    	 if(stu[i].getenglishscore()<=65.9&&stu[i].getenglishscore()>64)
    		 englishjd=1.5;
    	 if(stu[i].getenglishscore()<=63.9&&stu[i].getenglishscore()>=60)
    		 englishjd=1.0;
    	 if(stu[i].getenglishscore()<60)
    		 englishjd=0;
    	return englishjd;
     }
     static double netjd(int i) {
    	 double netjd=0;
    	 if(stu[i].getnetworkscore()>=90)
    		 netjd=4.0;
    	 if(stu[i].getnetworkscore()<=89.9&&stu[i].getnetworkscore()>85)
    		 netjd=3.7;
    	 if(stu[i].getnetworkscore()<=84.9&&stu[i].getnetworkscore()>82)
    		 netjd=3.2;
    	 if(stu[i].getnetworkscore()<=81.9&&stu[i].getnetworkscore()>78)
    		 netjd=3.0;
    	 if(stu[i].getnetworkscore()<=77.9&&stu[i].getnetworkscore()>75)
    		 netjd=2.7;
    	 if(stu[i].getnetworkscore()<=74.9&&stu[i].getnetworkscore()>72)
    		 netjd=2.3;
    	 if(stu[i].getnetworkscore()<=71.9&&stu[i].getnetworkscore()>68)
    		 netjd=2.0;
    	 if(stu[i].getnetworkscore()<=67.9&&stu[i].getnetworkscore()>66)
    		 netjd=1.7;
    	 if(stu[i].getnetworkscore()<=65.9&&stu[i].getnetworkscore()>64)
    		 netjd=1.5;
    	 if(stu[i].getnetworkscore()<=63.9&&stu[i].getnetworkscore()>=60)
    		 netjd=1.0;
    	 if(stu[i].getnetworkscore()<60)
    		 netjd=0;
    	return netjd;
     }
     static double datajd(int i) {
    	 double datajd=0;
    	 if(stu[i].getdatabasescore()>=90)
    		 datajd=4.0;
    	 if(stu[i].getdatabasescore()<=89.9&&stu[i].getdatabasescore()>85)
    		 datajd=3.7;
    	 if(stu[i].getdatabasescore()<=84.9&&stu[i].getdatabasescore()>82)
    		 datajd=3.2;
    	 if(stu[i].getdatabasescore()<=81.9&&stu[i].getdatabasescore()>78)
    		 datajd=3.0;
    	 if(stu[i].getdatabasescore()<=77.9&&stu[i].getdatabasescore()>75)
    		 datajd=2.7;
    	 if(stu[i].getdatabasescore()<=74.9&&stu[i].getdatabasescore()>72)
    		 datajd=2.3;
    	 if(stu[i].getdatabasescore()<=71.9&&stu[i].getdatabasescore()>68)
    		 datajd=2.0;
    	 if(stu[i].getdatabasescore()<=67.9&&stu[i].getdatabasescore()>66)
    		 datajd=1.7;
    	 if(stu[i].getdatabasescore()<=65.9&&stu[i].getdatabasescore()>64)
    		 datajd=1.5;
    	 if(stu[i].getdatabasescore()<=63.9&&stu[i].getdatabasescore()>=60)
    		 datajd=1.0;
    	 if(stu[i].getdatabasescore()<60)
    		 datajd=0;
    	return datajd;
     }
     static double softjd(int i) {
    	 double softjd=0;
    	 if(stu[i].getsoftwarescore()>=90)
    		 softjd=4.0;
    	 if(stu[i].getsoftwarescore()<=89.9&&stu[i].getsoftwarescore()>85)
    		 softjd=3.7;
    	 if(stu[i].getsoftwarescore()<=84.9&&stu[i].getsoftwarescore()>82)
    		 softjd=3.2;
    	 if(stu[i].getsoftwarescore()<=81.9&&stu[i].getsoftwarescore()>78)
    		 softjd=3.0;
    	 if(stu[i].getsoftwarescore()<=77.9&&stu[i].getsoftwarescore()>75)
    		 softjd=2.7;
    	 if(stu[i].getsoftwarescore()<=74.9&&stu[i].getsoftwarescore()>72)
    		 softjd=2.3;
    	 if(stu[i].getsoftwarescore()<=71.9&&stu[i].getsoftwarescore()>68)
    		 softjd=2.0;
    	 if(stu[i].getsoftwarescore()<=67.9&&stu[i].getsoftwarescore()>66)
    		 softjd=1.7;
    	 if(stu[i].getsoftwarescore()<=65.9&&stu[i].getsoftwarescore()>64)
    		 softjd=1.5;
    	 if(stu[i].getsoftwarescore()<=63.9&&stu[i].getsoftwarescore()>=60)
    		 softjd=1.0;
    	 if(stu[i].getsoftwarescore()<60)
    		 softjd=0;
    	return softjd;
     }
     static double averagejd(int k) {
    	 double ave,he1;
    	 he1=mathjd(k)*4+englishjd(k)*3+netjd(k)*4+datajd(k)*3+softjd(k)*2;
    	 return he1/16;
     }
     static void displayjd() {
    	 System.out.println("***********************************************************");
    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	 System.out.println("                  学生考试成绩绩点计算界面                                         ");
    	 System.out.println("***********************************************************");
    	 System.out.println("               请输入学生学号:XXXXXXXXXXXX	");
    	 System.out.println("***********************************************************");
    	 String str=in.next();
    	 boolean b1=true;
    	 DecimalFormat    df   = new DecimalFormat("#.00");
    	 for(int i=0;i<5;i++) {
    		 if(str.equals(stu[i].getstunumber())) {
    			 b1=false;
    			 System.out.println("***********************************************************");
    	    	 System.out.println("        石家庄铁道大学软件工程系学生学籍管理系统 2019 版             ");
    	    	 System.out.println("                  学生考试成绩绩点计算界面                                         ");
    	    	 System.out.println("***********************************************************");
    	    	 System.out.println("                学生学号:"+stu[i].getstunumber());
    	    	 System.out.println("                学生姓名:"+stu[i].getname());
    	    	 System.out.println("                  高等数学成绩绩点:"+mathjd(i));
    	    	 System.out.println("                  大学英语成绩绩点:"+englishjd(i));	    
    	    	 System.out.println("                  计算机网络成绩绩点:"+netjd(i));
    	    	 System.out.println("                  数据库成绩绩点:"+datajd(i));	         
    	    	 System.out.println("                  软件工程成绩绩点:"+softjd(i));
    	    	 System.out.print("                   你的平均学分绩点:");
    	    	 double ave2=averagejd(i);
    	    	 System.out.println(df.format(ave2));
    	    	 if(averagejd(i)>=2) {
    	    		 System.out.println("        提示信息:你的学分绩点已达到毕业要求!        ");
    	    	 }
    	    	 else {
    	    		 System.out.println("        提示信息:你的学分绩点不满足毕业要求!        ");
    	    	 }
    	    	 System.out.println("            该学生成绩已修改完毕,是否提交(Y/N)   ");
    	    	 String tijiao=in.next();
    	    	 if(tijiao.equals("Y")) {
    	    		 display();
    	    	 }
    	    	 else {}
    		 }
    	 }
    	 if(b1) {
    		 System.out.println("没有此学生!");
    		 displayjd();
    	 }
    	
     }
     static ScoreInformation[] stu=new ScoreInformation[10];
	public static void main(String[] args) {
		 for(int i=0;i<10;i++)
			 stu[i]=new ScoreInformation();
		stu[0].setstunumber("20183529");stu[0].setname("高帅");/*stu[0].setmathematicsscore(99);
		stu[0].setenglishscore(98);stu[0].setnetworkscore(97);stu[0].setdatabasescore(96);
		stu[0].setsoftwarescore(99);*/
		stu[1].setstunumber("20183333");stu[1].setname("tom");/*stu[1].setmathematicsscore(99);
		stu[1].setenglishscore(98);stu[1].setnetworkscore(97);stu[1].setdatabasescore(96);
		stu[1].setsoftwarescore(99);*/
		stu[2].setstunumber("20184444");stu[2].setname("jack");/*stu[2].setmathematicsscore(99);
		stu[2].setenglishscore(98);stu[2].setnetworkscore(97);stu[2].setdatabasescore(96);
		stu[2].setsoftwarescore(99);*/
		stu[3].setstunumber("20185555");stu[3].setname("amy");/*stu[3].setmathematicsscore(99);
		stu[3].setenglishscore(98);stu[3].setnetworkscore(97);stu[3].setdatabasescore(96);
		stu[3].setsoftwarescore(99);*/
		stu[4].setstunumber("20186666");stu[4].setname("cory");/*stu[4].setmathematicsscore(99);
		stu[4].setenglishscore(98);stu[4].setnetworkscore(97);stu[4].setdatabasescore(96);
		stu[4].setsoftwarescore(99);*/
		boolean b1=true;
		 while(b1) {
			display();
		int num=in.nextInt();
        switch(num) {
        	case 1:displayscorescan();
        	       break;
        	case 2:update();
        	       break;
        	case 3:displayjd();
        	       break;
        	case 4:displayexit();
        	       break;
        }
        }
	}

}

 程序设计思路:创建一个分数信息类,并创建七个数据成员,来存储学生的基本信息和各科分数,然后分别用四个函数来实现程序的基本功能:1成绩录入,2.成绩修改,3.绩点显示,4退出程序。将界面显示和具体功能分割开来,用不同的函数来实现。将一个大问题细小化,来分步完成。这样程序有条有理,查找错误的时候也非常方便。

 

 

 

 

 

原文地址:https://www.cnblogs.com/g414056667/p/11508456.html