为了能让代码更容易检查,我特意将所有关于界面显示的方法归类到Surface类里。这个类里只有显示界面的功能代码,无其他作用
三,Main类:
import java.util.Scanner;public class Main { static Surface x = new Surface(); //调用界面类 static Scanner in = new Scanner(System.in); public void stem1(ScoreInformation a[]){ //执行学生成绩录入操作 int temp1 = 0; x.inStun(); String m = in.next(); for(int i = 0; i < 5; i++){ if(a[i].getStunumber().equals(m)) { x.inMath(a[i]); double d1 = in.nextDouble(); a[i].setMath(d1); x.inEng(a[i]); double d2 = in.nextDouble(); a[i].setEng(d2); x.inNet(a[i]); double d3 = in.nextDouble(); a[i].setNet(d3); x.inData(a[i]); double d4 = in.nextDouble(); a[i].setData(d4); x.inSoft(a[i]); double d5 = in.nextDouble(); a[i].setSoft(d5); x.inall(a[i]); String c = in.next(); if(c.equals("N")){ a[i].setMath(0); a[i].setEng(0); a[i].setNet(0); a[i].setData(0); a[i].setSoft(0); } x.mainsur(); temp1 = 1; break; } } if(temp1 == 0) { System.out.println("该学号不存在"); x.mainsur(); } } public void stem2(ScoreInformation a[]){ //执行学生成绩修改操作。 int temp1 = 0; double r1,r2,r3,r4,r5; x.changeStun(); String m = in.next(); for(int i = 0; i < 5; i++){ if(a[i].getStunumber().equals(m)) { r1 = a[i].getMath(); r2 = a[i].getEng(); r3 = a[i].getNet(); r4 = a[i].getData(); r5 = a[i].getSoft(); x.outscore(a[i]); int c = in.nextInt(); switch(c){ case 1: x.changeMath(a[i]); double d1 = in.nextDouble(); a[i].setMath(d1); break; case 2: x.changeEng(a[i]); double d2 = in.nextDouble(); a[i].setEng(d2); break; case 3: x.changeNet(a[i]); double d3 = in.nextDouble(); a[i].setNet(d3); break; case 4: x.changeData(a[i]); double d4 = in.nextDouble(); a[i].setData(d4); break; case 5: x.changeSoft(a[i]); double d5 = in.nextDouble(); a[i].setSoft(d5); break; default: System.out.println("无该选项,返回主界面"); x.mainsur(); break; } x.overchange(a[i]); String h = in.next(); if(h.equals("N")){ a[i].setMath(r1); a[i].setEng(r2); a[i].setNet(r3); a[i].setData(r4); a[i].setSoft(r5); } x.mainsur(); temp1 = 1; break; } } if(temp1 == 0) { System.out.println("该学号不存在"); x.mainsur(); } } public void stem3(ScoreInformation a[]){ //执行绩点计算操作 Main v = new Main(); double R; double r1,r2,r3,r4,r5; double x1,x2,x3,x4,x5; x.startgrade(); String m = in.next(); for(int i = 0; i < 5; i++){ if(a[i].getStunumber().equals(m)) { r1 = a[i].getMath();x1 = v.Gpoint(r1); r2 = a[i].getEng();x2 = v.Gpoint(r2); r3 = a[i].getNet();x3 = v.Gpoint(r3); r4 = a[i].getData();x4 = v.Gpoint(r4); r5 = a[i].getSoft();x5 = v.Gpoint(r5); R = (x1*r1+x2*r2+x3*r3+x4*r4+x5*r5)/(r1+r2+r3+r4+r5); if(R>=2){ x.endscore1(a[i], R); }else{ x.endscore2(a[i], R); } String q = in.next(); if(q.equals("Y")){ x.mainsur(); } break; } } } public double Gpoint(double d){ //返回学分对应的绩点 double e = 0; if(d>=90.0) e = 4.0; else if(d>=85&&d<=89.9) e = 3.7; else if(d>=82&&d<=84.9) e = 3.3; else if(d>=78&&d<=81.9) e = 3.0; else if(d>=75&&d<=77.9) e = 2.7; else if(d>=72&&d<=74.9) e = 2.3; else if(d>=68&&d<=71.9) e = 2.0; else if(d>=66&&d<=67.9) e = 1.7; else if(d>=64&&d<=65.9) e = 1.5; else if(d>=60&&d<=63.9) e = 1.0; else if(d<60) e = 0; return e; } public static void main(String[] args) { Main u = new Main(); ScoreInformation a[] = new ScoreInformation[5]; a[0] = new ScoreInformation(); a[1] = new ScoreInformation("20180001","小赵"); a[2] = new ScoreInformation("20180002","小张"); a[3] = new ScoreInformation("20180003","小王"); a[4] = new ScoreInformation("20180004","小李"); int temp = 0; x.mainsur(); int T = in.nextInt(); while(temp == 0){ //重复调用 switch(T){ case 1: u.stem1(a); T = in.nextInt(); break; case 2: u.stem2(a); T = in.nextInt(); break; case 3: u.stem3(a); T = in.nextInt(); break; case 4: x.endsur(); temp = 1; break; default: System.out.println("该选项不存在"); x.mainsur(); temp = 1; break; } } in.close(); }}