Java實現高校教務系統
本文實例為大傢分享瞭Java實現高校教務系統的具體代碼,供大傢參考,具體內容如下
需求:建立一個教務管理系統,為學生和教師提供不同的功能
//簡單利用javase基礎做出後端框架,後期再利用mysql數據庫以及Spring cloud完善
父類:
public class people { private String name; private int age; private String sex; public people() { } public people(String name, int age, String sex) { this.name = name; this.age = age; this.sex = sex; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } }
學生類:
public class student extends people{ private String classname; private String studyid; private String chengji=""; private String kebiao=""; private String jiguo=""; private String studypassword; public student() { } public student(String name, int age, String sex, String classname, String studyid, String studypassword) { super(name, age, sex); this.classname = classname; this.studyid = studyid; this.studypassword = studypassword; } public String getClassname() { return classname; } public void setClassname(String classname) { this.classname = classname; } public String getStudyid() { return studyid; } public void setStudyid(String studyid) { this.studyid = studyid; } public String getStudypassword() { return studypassword; } public void setStudypassword(String studypass) { this.studypassword = studypassword; } public String getChengji() { return chengji; } public void setChengji(String chengji) { this.chengji = chengji; } public String getKebiao() { return kebiao; } public void setKebiao(String kebiao) { this.kebiao = kebiao; } public String getJiguo() { return jiguo; } public void setJiguo(String jiguo) { this.jiguo = jiguo; } }
教師類:
public class teacher extends people{ private String teachclass; private String teachid; private String teachpassword; public teacher() { } public teacher(String name, int age, String sex, String teachclass, String teachid, String teachpassword) { super(name, age, sex); this.teachclass = teachclass; this.teachid = teachid; this.teachpassword = teachpassword; } public String getTeachclass() { return teachclass; } public void setTeachclass(String teachclass) { this.teachclass = teachclass; } public String getTeachid() { return teachid; } public void setTeachid(String teachid) { this.teachid = teachid; } public String getTeachpassword() { return teachpassword; } public void setTeachpassword(String teachpassword) { this.teachpassword = teachpassword; } }
源碼:
import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class test { public static void main(String[] args) { ArrayList<student> students = new ArrayList<>(); ArrayList<teacher> teachers = new ArrayList<>(); main(teachers,students); end(); } public static void main(ArrayList<teacher>teachers,ArrayList<student>students) { Scanner sc = new Scanner(System.in); System.out.println("----------歡迎來到中彬教育後臺管理系統-----------"); while (true) { System.out.println("請輸入您的身份:1.老師 2.學生 或者按0退出系統"); int commend = sc.nextInt(); switch (commend) { case 1: teach(students,teachers,sc); break; case 2: student(students,sc); break; case 0: return; default: System.out.println("輸入不合法!請重新輸入,或按0退出"); } } } public static void teach(ArrayList<student>students,ArrayList<teacher>teachers,Scanner sc) { System.out.println("----------歡迎進入教師界面----------"); while (true) { System.out.println("請選擇您的操作:"); System.out.println("1.教師登錄"); System.out.println("2.教師註冊"); System.out.println("3.返回"); int commend = sc.nextInt(); switch (commend) { case 1: teacherdenglu(students,teachers,sc); break; case 2: teacherzhuce(teachers,sc); break; case 3: return; default: System.out.println("不存在該功能!"); } } } public static void student( ArrayList <student> students ,Scanner sc) { System.out.println("----------歡迎進入學生界面----------"); while (true) { System.out.println("請選擇您的操作:"); System.out.println("1.學生登錄"); System.out.println("2.學生註冊"); System.out.println("3.返回"); int commend = sc.nextInt(); switch (commend) { case 1: studentdenglu(students,sc); break; case 2: studentzhuce(students,sc); break; case 3: return; default: System.out.println("不存在該功能!"); } } } public static void studentdenglu(ArrayList<student>students,Scanner sc) { System.out.println("----------歡迎進入學生登錄系統----------"); String studyid; String password; String code; String code2 =yanzhengma(); if(students.size()==0) { System.out.println("系統中無學生信息!,請先註冊學生賬戶"); } else { while (true) { System.out.println("請輸入學號:"); studyid = sc.next(); student acc =getstudyid(studyid,students); if(acc!=null) { System.out.println("請輸入密碼:"); password= sc.next(); if(password.equals(acc.getStudypassword())) { System.out.println("請輸入驗證碼"); System.out.println(code2); code= sc.next(); if(code.equals(code2)) { System.out.println("登錄成功!,進入學生"+acc.getName()+"的主頁"); studentmain(students,sc,acc); return; } else { System.out.println("驗證碼輸入錯誤!"); } } else { System.out.println("密碼錯誤!"); } } else { System.out.println("不存在該學號!"); } } } } public static void studentmain(ArrayList<student>students,Scanner sc,student s) { while (true) { System.out.println("----------學生"+s.getName()+"的主頁----------"); System.out.println("選擇操作:"); 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.println("7.修改密碼"); int commend= sc.nextInt(); switch (commend) { case 1: student1(students,s); break; case 2: student2(students,s); break; case 3: student3(students,s,sc); break; case 4: student4(students,s); break; case 5: over(sc,students,s); break; case 6: return; case 7: xiugai(students,s,sc); default: System.out.println("不存在該功能!"); } } } public static void teachmain(ArrayList<student>students,ArrayList<teacher>teachers,Scanner sc ,teacher t) { while (true) { System.out.println("----------教師"+t.getName()+"的主頁-----------"); System.out.println("選擇操作:"); 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.println("7.退出系統"); System.out.println("8.修改密碼"); int commend = sc.nextInt(); switch (commend) { case 1: teach1(teachers,t); break; case 2: teach2(teachers,t,sc); break; case 3: teach3(students,sc); break; case 4: teach4(students,sc); break; case 5: teach5(students,sc); break; case 6: over2(sc,teachers,t); break; case 7: return; case 8: xiugai2(teachers,t,sc); break; default: System.out.println("功能不存在!"); break; } } } public static void studentzhuce(ArrayList<student>students,Scanner sc) { System.out.println("----------歡迎進入學生註冊系統----------"); System.out.println("請輸入您的姓名:"); String name = sc.next(); System.out.println("請輸入年齡:"); int age = sc.nextInt(); String sex; while (true) { System.out.println("請輸入性別:"); sex = sc.next(); if (sex.equals("男") || sex.equals("女")) { break; } else System.out.println("性別輸入不合法!請重新輸入"); } System.out.println("請輸入班級名:"); String classname = sc.next(); while (true) { System.out.println("請輸入學號:"); String studyid = sc.next(); String password; while (true) { System.out.println("請輸入密碼:"); password = sc.next(); System.out.println("請再次輸入密碼:"); String password2 = sc.next(); if (password.equals(password2)) { break; } else { System.out.println("兩次輸入密碼不一致!請重新輸入!"); } } student s = new student(name, age, sex, classname, studyid, password); System.out.println("您的信息如下:"); System.out.println(classname + "\t\t\t" + studyid + "\t\t\t" + name + "\t\t\t" + age + "\t\t\t" + sex); students.add(s); break; } } private static void teacherdenglu(ArrayList<student>students,ArrayList<teacher>teachers,Scanner sc) { System.out.println("----------歡迎進入教師登錄系統----------"); String teachid; String password; String code; String code2 =yanzhengma(); if(teachers.size()==0) { System.out.println("系統中無教師信息!,請先註冊賬戶"); } else { while (true) { System.out.println("請輸入職工號:"); teachid = sc.next(); teacher acc =getteachid(teachid,teachers); if(acc!=null) { System.out.println("請輸入密碼:"); password= sc.next(); if(password.equals(acc.getTeachpassword())) { System.out.println("請輸入驗證碼"); System.out.println(code2); code= sc.next(); if(code.equals(code2)) { System.out.println("登錄成功!,進入教師"+acc.getName()+"的主頁"); teachmain(students,teachers,sc,acc); return; } else { System.out.println("驗證碼輸入錯誤!"); } } else { System.out.println("密碼錯誤!"); } } else { System.out.println("不存在該職工號!"); } } } } private static void teacherzhuce(ArrayList<teacher>teachers,Scanner sc) { System.out.println("----------歡迎進入教師註冊系統----------"); System.out.println("請輸入您的姓名:"); String name = sc.next(); System.out.println("請輸入年齡:"); int age = sc.nextInt(); String sex; while (true) { System.out.println("請輸入性別:"); sex = sc.next(); if (sex.equals("男") || sex.equals("女")) { break; } else System.out.println("性別輸入不合法!請重新輸入"); } System.out.println("請輸入教學班級名:"); String teacherclass = sc.next(); while (true) { System.out.println("請輸入職工號:"); String teachid = sc.next(); String password; while (true) { System.out.println("請輸入密碼:"); password = sc.next(); System.out.println("請再次輸入密碼:"); String password2 = sc.next(); if (password.equals(password2)) { break; } else { System.out.println("兩次輸入密碼不一致!請重新輸入!"); } } teacher s = new teacher(name, age, sex, teacherclass, teachid, password); System.out.println("您的信息如下:"); System.out.println(teacherclass + "\t\t\t" + teachid + "\t\t\t" + name + "\t\t\t" + age + "\t\t\t" + sex); teachers.add(s); break; } } public static void student1(ArrayList<student>students,student s) { System.out.println("----------基本信息----------"); System.out.println("學生姓名:"+s.getName()); System.out.println("學生班級:"+s.getClassname()); System.out.println("學生學號:"+s.getStudyid()); System.out.println("學生年齡:"+s.getAge()); System.out.println("學生性別:"+s.getSex()); } public static void student2(ArrayList<student>students,student s) { System.out.println("學生"+s.getName()+"的成績查詢"); System.out.println("科目"+"\t\t\t"+"成績"+"\t\t\t"+"績點"); System.out.println(s.getChengji()); } public static void student3(ArrayList<student>students,student s,Scanner sc) { System.out.println("課表查詢:"); System.out.println("班級"+s.getClassname()+"的"+"課表為"); System.out.println(s.getKebiao()); } public static void student4(ArrayList<student>students,student s) { System.out.println("----------記過查詢----------"); System.out.println(s.getName()+"的記過為"+s.getJiguo()+"\n"); } public static void over(Scanner sc,ArrayList<student>students,student s) { System.out.println("是否確認註銷賬戶?按1確認,按2取消註銷"); int tf = sc.nextInt(); if (tf == 1) { students.remove(s); System.out.println("註銷成功!"); } else { System.out.println("取消註銷"); } } public static void over2(Scanner sc,ArrayList<teacher>teachers,teacher s) { System.out.println("是否確認註銷賬戶?按1確認,按2取消註銷"); int tf = sc.nextInt(); if (tf == 1) { teachers.remove(s); System.out.println("註銷成功!"); } else { System.out.println("取消註銷"); } } public static void teach1(ArrayList<teacher>teachers,teacher s) { System.out.println("----------基本信息----------"); System.out.println("教師名稱:"+s.getName()); System.out.println("教師年齡:"+s.getAge()); System.out.println("教師性別:"+s.getSex()); System.out.println("教師職工號:"+s.getTeachid()); System.out.println("教師教學班級:"+s.getTeachclass()); } public static void teach2(ArrayList<teacher>teachers,teacher s,Scanner sc) { System.out.println("----------教學課程----------"); System.out.println(s.getTeachclass()); System.out.println("添加請按1,修改請按2,退出按0"); int commend = sc.nextInt(); switch (commend) { case 1: System.out.println("輸入要添加的課程:"); String addclass = sc.next(); s.setTeachclass(addclass+","+s.getTeachclass()); System.out.println("修改成功!新課程是"+s.getTeachclass()); break; case 2: System.out.println("輸入要修改後的課程:"); String newclass =sc.next(); s.setTeachclass(newclass); System.out.println("修改成功!新課程是"+s.getTeachclass()); break; case 0: return; default: System.out.println("功能不存在!"); } } public static void teach3(ArrayList<student>students,Scanner sc) { System.out.println("----------添加成績----------"); while (true) { System.out.println("請輸入學生學號:"); String tostudyid = sc.next(); student tf = getstudyid(tostudyid, students); if (tf != null) { for (int i = 0; i < students.size(); i++) { student c = students.get(i); if (c.getStudyid().equals(tostudyid)) { System.out.println("輸入課程名稱:"); String kecheng = sc.next(); System.out.println("輸入成績:"); double score = sc.nextDouble(); System.out.println("輸入績點:"); double jidian =sc.nextDouble(); String chengji=kecheng+"\t\t\t"+score+"\t\t\t"+jidian; c.setChengji(c.getChengji()+"\n"+chengji); System.out.println("添加成功!"); System.out.println("繼續添加按1,退出添加按0"); int commend=sc.nextInt(); switch (commend) { case 1: break; case 0: return; } } } } else { System.out.println("學生不存在!"); return; } } } public static void teach4(ArrayList<student>students,Scanner sc) { System.out.println("----------添加課表----------"); System.out.println("請輸入班級名稱:"); String banji= sc.next(); student acc=getclass(banji,students); if(acc!=null) { System.out.println("請輸入年級:1.大一上 2.大一下 3.大二上 4.大二下 5.大三上 6.大三下"); String commend=sc.next(); System.out.println("班級"+acc.getClassname()+"的"+commend+"課表為"); teachtuo(students,acc,sc); } else System.out.println("班級不存在!"); } public static void teachtuo(ArrayList<student>students,student s ,Scanner sc) { System.out.println("請輸入星期:1,2,3,4,5"); int commend = sc.nextInt(); System.out.println("請輸入1-2節:"); String sub12 = sc.next(); System.out.println("請輸入3-4節:"); String sub34= sc.next(); System.out.println("請輸入5-6節:"); String sub56=sc.next(); System.out.println("請輸入7-8節:"); String sub78=sc.next(); String newkebiao ="星期"+commend+":\t\t"+sub12+"\t\t"+sub34+"\t\t"+sub56+"\t\t"+sub78; s.setKebiao(newkebiao+s.getKebiao()); } public static void teach5(ArrayList<student>students,Scanner sc) { System.out.println("----------添加記過----------"); while (true) { System.out.println("請輸入學生學號:"); String tostudyid = sc.next(); student tf = getstudyid(tostudyid, students); if (tf != null) { for (int i = 0; i < students.size(); i++) { student c = students.get(i); if (c.getStudyid().equals(tostudyid)) { System.out.println("輸入記過:"); String ji = sc.next(); c.setJiguo(tf.getJiguo()+ji); System.out.println("添加成功!"); System.out.println("繼續添加按1,退出添加按0"); int commend=sc.nextInt(); switch (commend) { case 1: break; case 0: return; } } } } else { System.out.println("學生不存在!"); return; } } } private static String yanzhengma() { Random r = new Random(); String ku ="0123456789"; String code=""; for (int i = 0; i < 4; i++) { int index = r.nextInt(ku.length()); char c = ku.charAt(index); code+=c; } return code; } //查詢班級是否存在 public static student getclass(String classname,ArrayList<student>students) { for (int i = 0; i < students.size(); i++) { student s =students.get(i); if(s.getClassname().equals(classname)) { return s; } } return null; } //查詢學生賬戶是否存在 private static student getstudyid(String studyid,ArrayList<student>students) { for (int i = 0; i < students.size(); i++) { student s = students.get(i); if (s.getStudyid().equals(studyid)) { return s; } } return null; } //查詢教師賬戶是否存在 public static teacher getteachid(String teachid,ArrayList<teacher>teachers) { for (int i = 0; i < teachers.size(); i++) { teacher s =teachers.get(i); if(s.getTeachid().equals(teachid)) { return s; } } return null; } public static void xiugai(ArrayList<student>students , student s,Scanner sc) { System.out.println("修改密碼操作"); while (true) { System.out.println("請輸入原密碼"); String oldpassword = sc.next(); if (oldpassword.equals(s.getStudypassword())) { System.out.println("請輸入新密碼:"); String newpassword= sc.next(); System.out.println("請再次輸入新密碼:"); String newpassword2= sc.next(); if(newpassword.equals(newpassword2)) { System.out.println("修改成功!"); s.setStudypassword(newpassword); return; } else System.out.println("兩次密碼不一致!請重新修改!"); } else { System.out.println("原密碼錯誤!"); return; } } } public static void xiugai2(ArrayList<teacher>teachers , teacher s,Scanner sc) { System.out.println("修改密碼操作"); while (true) { System.out.println("請輸入原密碼"); String oldpassword = sc.next(); if (oldpassword.equals(s.getTeachpassword())) { System.out.println("請輸入新密碼:"); String newpassword= sc.next(); System.out.println("請再次輸入新密碼:"); String newpassword2= sc.next(); if(newpassword.equals(newpassword2)) { System.out.println("修改成功!"); s.setTeachpassword(newpassword); return; } else System.out.println("兩次密碼不一致!請重新修改!"); } else { System.out.println("原密碼錯誤!"); return; } } } public static void end() { System.out.println("已退出系統!歡迎下次進入"); } }
以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。