import java.util.Scanner; public class Syscontrol{ public static void main(String[] args) { UI.menu(); } } class UI { public static void menu() { System.out.println("******************学生个人成绩管理系统***********"); System.out.printf("\n", null); System.out.println(" 1、成绩管理"); System.out.println(" 2、信息管理"); System.out.println(" 3、退出系统"); System.out.printf("\n", null); System.out.println("************************************************"); System.out.println("请输入功能编号(1-3):"); Scanner r0 = new Scanner(System.in); int i = r0.nextInt(); switch(i){ case 1: grademenu(); break; case 2: stumenu(); break; case 3: System.out.println("再见!"); break; default: System.out.println("请输入数字1到3"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } menu(); break; } r0.close(); } private static void grademenu() { StudentService stulist=new StudentService(); System.out.println("******************学生个人成绩系统***************"); System.out.printf("\n", null); System.out.println(" 1、增加成绩"); System.out.println(" 2、删除成绩"); System.out.println(" 3、修改成绩"); System.out.println(" 4、显示成绩"); System.out.println(" 5、汇总成绩"); System.out.println(" 6、返回上一系统"); System.out.printf("\n", null); System.out.println("************************************************"); System.out.println("请输入功能编号(1-6):"); Scanner r1 = new Scanner(System.in); int s = r1.nextInt(); switch(s){ case 1: stulist.addgrades(); Syscontrol.main(null); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } break; case 2: stulist.delgrades(); Syscontrol.main(null); break; case 3: stulist.editgrades(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Syscontrol.main(null); break; case 4: stulist.findgrades(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Syscontrol.main(null); break; case 5: stulist.allgrades(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Syscontrol.main(null); break; case 6: grademenu(); break; default: System.out.println("请输入数字1到6"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } stumenu(); break; } r1.close(); } private static void stumenu() { StudentService stulist=new StudentService(); System.out.println("******************学生个人成绩管理系统***********"); System.out.printf("\n", null); System.out.println(" 1、显示学生信息"); System.out.println(" 2、修改学生信息"); System.out.println(" 3、返回上一系统"); System.out.printf("\n", null); System.out.println("************************************************"); System.out.println("请输入功能编号(1-3):"); Scanner r2 = new Scanner(System.in); int t = r2.nextInt(); switch(t){ case 1: stulist.showstu(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Syscontrol.main(null); break; case 2: stulist.editstu(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Syscontrol.main(null); break; case 3: menu(); break; default: System.out.println("请输入数字1到3"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } stumenu(); break; } r2.close(); } } class Student{ private String stuno; private String name; private String classes; private String rtime; Scores subjects[]; private static int itemCount =0; Student(){ itemCount++; } Student(String stuno,String name,String classes,String rtime){ this.stuno = stuno; this.name = name; this.classes = classes; this.rtime = rtime; itemCount++; } Student(Student aItem){ this(aItem.stuno,aItem.name,aItem.classes,aItem.rtime); itemCount++; } public Student(String stuno,String name,String classes,String rtime, Scores[] sub) { this.stuno = stuno; this.name = name; this.classes = classes; this.rtime = rtime; this.subjects=sub; itemCount++; } public String getStuno() { return stuno; } public void setStuno(String stuno) { this.stuno = stuno; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getClasses() { return classes; } public void setClasses(String classes) { this.classes = classes; } public String getRtime() { return rtime; } public void setRtime(String rtime) { this.rtime = rtime; } public static int getItemCount() { return itemCount; } public Scores[] getSubjects() { return subjects; } public void setSubjects(Scores[] subjects) { this.subjects = subjects; } public String toString(){ return stuno+" "+name+" "+classes+" "+rtime; } } class Scores{ private String cno; private String cname; private String cgrades; private String cscore; Scores(){ } Scores(String cno,String cname,String cgrades,String cscore){ this.cno = cno; this.cname = cname; this.cgrades=cgrades; this.cscore=cscore; } public String getCno() { return cno; } public void setCno(String cno) { this.cno = cno; } public String getCname() { return cname; } public void setCname(String cname) { this.cname = cname; } public String getCscore() { return cscore; } public void setCscore(String cscore) { this.cscore = cscore; } public String getCgrades() { return cgrades; } public void setCgrades(String cgrades) { this.cgrades = cgrades; } } class StudentService{ private Student stu[]=new Student[100]; private Scores sub[]=new Scores[100]; private static int stutotal; private static int subtotal; public static int getStutotal() { return stutotal; } public static int getSubtotal() { return subtotal; } public StudentService(){ sub[0]=new Scores("1","Math"," 60","4"); sub[1]=new Scores("2","English"," 60","3.5"); sub[2]=new Scores("3","Chinese"," 60","3"); subtotal=3; stu[0]=new Student("1","xu","12-1","2012",sub); stu[1]=new Student("2","yu","12-1","2012",sub); stu[2]=new Student("3","su","12-1","2012",sub); stutotal=3; } public boolean showstu(){ System.out.println("请输入学生学号:"); Scanner sc = new Scanner(System.in); String i = sc.nextLine(); //sc.close(); int j; for(j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0) break; } if(j<stutotal) { System.out.println("学号为"+i+"信息为"+stu[j].toString()); return true; }else { System.out.println("未找到您输入的学生,请检查!"); return false; } } public void showstu(String i){ int j; for(j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0) break; } if(j<stutotal) System.out.println("学号为"+i+"信息为"+stu[j].toString()); } public void editstu(){ System.out.println("请输入要修改的学生学号:"); Scanner sc = new Scanner(System.in); String i = sc.nextLine(); int j; for(j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0) break; } if(j<stutotal) { System.out.println("学号为"+i+"信息为"+stu[j].toString()); System.out.println("请输入新的学生信息,输入格式为学号,姓名,班级,入学年份。如:1 xu 12-1 2012"); String input =sc.nextLine(); String[] additem=input.split(" "); if(additem.length==4){ delstu(i); addstu(new Student(additem[0],additem[1],additem[2],additem[3])); System.out.println("修改成功!"); showstu(i); //sc.close(); } } else { System.out.println("未找到您输入的学生,请检查!"); //sc.close(); } } public void delstu(String i) { int k=-1; for(int j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0) k=j; } if(k!=-1){ for(int s=k;s<stutotal-1;s++) stu[s]=stu[s+1]; stutotal--; stu[stutotal]=null; } } public void addstu(Student student){ stu[stutotal]=new Student(student); stutotal++; } public void addgrades(){ System.out.println("请输入学生学号:"); Scanner sc = new Scanner(System.in); String i = sc.nextLine(); for(int j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0){ System.out.println("请输入科目名称:"); String m = sc.nextLine(); for(int j1=0;j1<stutotal;j1++){ if(stu[j].subjects[j1].getCname().compareTo(m)==0){ System.out.println("请输入成绩:"); String n = sc.nextLine(); stu[j].subjects[j1].setCgrades(n); System.out.println("成绩录入成功!"); System.out.println("学号为"+i+"科目"+m+"成绩为"+stu[j].subjects[j1].getCgrades()); } } break; } } //sc.close(); } public void editgrades(){ System.out.println("请输入学生学号:"); Scanner sc = new Scanner(System.in); String i = sc.nextLine(); for(int j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0){ System.out.println("请输入科目名称:"); String m = sc.nextLine(); for(int j1=0;j1<stutotal;j1++){ if(stu[j].subjects[j1].getCname().compareTo(m)==0){ System.out.println("学号为"+i+"科目"+m+"成绩为"+stu[j].subjects[j1].getCgrades()); System.out.println("请输入新的成绩:"); String n = sc.nextLine(); stu[j].subjects[j1].setCgrades(n); System.out.println("新成绩录入成功!"); System.out.println("学号为"+i+"科目"+m+"新成绩为"+stu[j].subjects[j1].getCgrades()); } } break; } } // sc.close(); } public void delgrades(){ System.out.println("请输入学生学号:"); Scanner sc = new Scanner(System.in); String i = sc.nextLine(); for(int j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0){ System.out.println("请输入科目名称:"); String m = sc.nextLine(); for(int j1=0;j1<stutotal;j1++){ if(stu[j].subjects[j1].getCname().compareTo(m)==0){ System.out.println("学号为"+i+"科目"+m+"成绩为"+stu[j].subjects[j1].getCgrades()); System.out.println("确认删除吗?(1/0):"); int n = sc.nextInt(); if(n==1) { stu[j].subjects[j1].setCgrades(null); System.out.println("删除成功!"); System.out.println("学号为"+i+"科目"+m+"成绩为"+stu[j].subjects[j1].getCgrades()); } } } break; } } //sc.close(); } public void findgrades(){ System.out.println("请输入学生学号:"); Scanner sc = new Scanner(System.in); String i = sc.nextLine(); for(int j=0;j<stutotal;j++){ if(stu[j].getStuno().compareTo(i)==0){ System.out.println("请输入科目名称:"); String m = sc.nextLine(); for(int j1=0;j1<stutotal;j1++){ if(stu[j].subjects[j1].getCname().compareTo(m)==0){ System.out.println("学号为"+i+"科目"+m+"成绩为"+stu[j].subjects[j1].getCgrades()); } } break; } } //sc.close(); } public void allgrades() { for(int j=0;j<stutotal;j++){ System.out.println(stu[j].getName()); for(int j1=0;j1<subtotal;j1++) System.out.println(stu[j].subjects[j1].getCname()+"成绩为"+stu[j].subjects[j1].getCgrades()); } }
时间: 2024-10-04 02:30:49