Java 實現簡易教務管理系統的程式碼
阿新 • • 發佈:2020-07-29
Main.java
import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println("\t\t簡易教務管理系統"); System.out.println("1、錄入學生\t2、顯示學生\t3、錄入課程\t4、顯示課程\t5、錄入教師" +"\t6、顯示教師\t7、學生選課\t8、教師錄入成績\t9、教師排課\t10、授課評價\t0、退出"); Student[] students=null; Course courses[]=null; Teacher teachers[]=null; Operator operator=new Operator(); Scanner scan= new Scanner(System.in); itcase: while (true) { //顯示系統主選單 System.out.print("請選擇功能選單:"); int choice = scan.nextInt();// 接收使用者的選擇 switch(choice){ case 1: // 輸入學生資訊 System.out.println("請輸入學生數:"); int n = scan.nextInt(); students = new Student[n]; operator.addStudents(students); break; case 2: // 顯示全部學生資訊 operator.displayStudents(students); break; case 3://錄入課程 System.out.println("請輸入課程數:"); n = scan.nextInt(); courses = new Course[n]; operator.addCourses(courses); break; case 4: // 顯示課程 operator.displayCourses(courses); break; case 5: // 錄入教師 System.out.println("請輸入教師數:"); n = scan.nextInt(); teachers = new Teacher[n]; operator.addTeachers(teachers); break; case 6:// 顯示教師 operator.displayTeachers(teachers); break; case 7:// 學生選課 operator.stuSelectCourses(students,courses); break; case 8:// 錄入成績 operator.inputScores(students); break; case 9:// 教師排課 operator.assignTeachCourses(teachers,courses); break; case 10:// 授課評價 operator.inputEvaluate(teachers); break; case 0:// 退出 break itcase; default: System.out.println("非法命令!"); } } }
Course.java
public class Course { private String courseId;//課程號 private String courseName;//課程名稱 private double credit;//學分 //構造方法 Course(){ } Course(String courseId,String courseName,double credit){ this.setCourseId(courseId); this.setCourseName(courseName); this.setCredit(credit); } public String getCourseId() { return courseId; } public void setCourseId(String courseId) { this.courseId = courseId; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public double getCredit() { return credit; } public void setCredit(double credit) { this.credit = credit; } }
Operator.java
import java.util.Scanner; public class Operator { Scanner scan; Operator(){ scan= new Scanner(System.in); } //錄入課程 public void addCourses(Course[] courses){ System.out.println("請輸入學生資訊:格式為課程號,課程名,學分"); String str; String sInfor[]; for(int i=0;i<courses.length;i++){ str=scan.next(); sInfor=str.split(","); courses[i]=new Course(sInfor[0],sInfor[1],Double.parseDouble(sInfor[2])); } } //顯示所有課程 public void displayCourses(Course[] courses){ for(int i=0;i<courses.length;i++){ System.out.println("課程號:"+courses[i].getCourseId()+",課程名:"+courses[i].getCourseName() +",學分:"+courses[i].getCredit()); } } //錄入學生 public void addStudents(Student[] students){ System.out.println("請輸入學生資訊:格式為學號,姓名,性別,電話,地址,年齡"); String str; String sInfor[]; for(int i=0;i<students.length;i++){ str=scan.next(); sInfor=str.split(","); students[i]=new Student(sInfor[0],sInfor[2],sInfor[3],sInfor[4],Integer.parseInt(sInfor[5])); } } //顯示學生所有資訊 public void displayStudents(Student[] students){ for(int i=0;i<students.length;i++){ System.out.println("學號:"+students[i].getStuId()+",姓名:"+students[i].getStuName() +",性別:"+students[i].getSex()+",電話:"+students[i].getTel() +",住址:"+students[i].getAddress()+",年齡:"+students[i].getAge()); if(students[i].selCourse!=null){ for(int j=0;j<students[i].selCourse.length;j++){ System.out.println("\t\t課程編號:"+students[i].selCourse[j].courseId+",成績:" +students[i].selCourse[j].grade); } } } } //錄入教師 public void addTeachers(Teacher[] teachers){ System.out.println("請輸入教師資訊:格式為工號,職稱,年齡"); String str; String sInfor[]; for(int i=0;i<teachers.length;i++){ str=scan.next(); sInfor=str.split(","); teachers[i]=new Teacher(sInfor[0],Integer.parseInt(sInfor[5])); } } //顯示教師所有資訊 public void displayTeachers(Teacher[] teachers){ for(int i=0;i<teachers.length;i++){ System.out.println("工號:"+teachers[i].getTeaId()+",姓名:"+teachers[i].getTeaName() +",性別:"+teachers[i].getSex()+",電話:"+teachers[i].getTel() +",職稱:"+teachers[i].getProfessor()+",年齡:"+teachers[i].getAge()); if(teachers[i].teachCourse!=null){ for(int j=0;j<teachers[i].teachCourse.length;j++){ System.out.println("\t\t課程編號:"+teachers[i].teachCourse[j].courseId+",授課評價:"+teachers[i].teachCourse[j].evaluate); } } } } //學生選課 public void stuSelectCourses(Student[] students,Course[] courses){ System.out.println(); System.out.println("\t課程資訊系如下:"); for(int i=0;i<courses.length;i++){ System.out.println("課程號:"+courses[i].getCourseId()+"\t"+"課程名稱:" +courses[i].getCourseName()); } System.out.println(); System.out.println("請選擇選修課程,格式為:課程號1,課程號2,......"); for(int i=0;i<students.length;i++){ System.out.println("學號:"+students[i].getStuId()+",姓名:" +students[i].getStuName()+" 選課:"); String str=scan.next(); String[] cIds=str.split(","); students[i].setSelCourse(cIds); } } //教師排課 public void assignTeachCourses(Teacher[] teachers,Course[] courses){ System.out.println(); System.out.println("\t課程資訊系如下:"); for(int i=0;i<courses.length;i++){ System.out.println("課程號:"+courses[i].getCourseId() +"\t"+"課程名稱:"+courses[i].getCourseName()); } System.out.println(); System.out.println("請選擇課程,格式為:課程號1,......"); for(int i=0;i<teachers.length;i++){ System.out.println("工號:"+teachers[i].getTeaId() +",姓名:"+teachers[i].getTeaName()+" 排課:"); String[] cIds=scan.next().split(","); teachers[i].setTeachCourse(cIds); } } //教師錄入成績 public void inputScores(Student[] students){ for(int i=0;i<students.length;i++){ for(int j=0;j<students[i].selCourse.length;j++){ System.out.println("請輸入學號:"+students[i].getStuId() +",姓名:"+students[i].getStuName() +",課程編號為:"+students[i].selCourse[j].courseId+"的成績:"); students[i].selCourse[j].grade=scan.nextDouble(); } } } //教師授課評價 public void inputEvaluate(Teacher[] teachers){ for(int i=0;i<teachers.length;i++){ for(int j=0;j<teachers[i].teachCourse.length;j++){ System.out.println("請輸入工號:"+teachers[i].getTeaId()+",姓名:"+teachers[i].getTeaName() +",課程編號為:"+teachers[i].teachCourse[j].courseId+"的授課評價:"); teachers[i].teachCourse[j].evaluate=scan.next(); } } } //刪除某門課程 public void delCourses(Course[] courses){ System.out.println("請輸入要刪除課程的編號:"); String courseId=scan.next(); for(int i=0;i<courses.length;i++){ if(courses[i].getCourseId().equals(courseId)){ courses[i]=null; } } } }
Student.java
public class Student { //設定Student類的屬性 private String stuId; //學號 private String stuName; //姓名 private String sex; //性別 private String tel; //電話號碼 private String address; //地址 private int age; //年齡 SelectCourse[] selCourse; //選修課程 //構造方法 Student(){ } Student(String stuId,String stuName){ this.stuId=stuId; this.stuName=stuName; } Student(String stuId,String stuName,String sex,String tel,String address,int age){ this(stuId,stuName); //this的用法 this.sex=sex; this.tel=tel; this.address=address; //地址 this.age=age; } public String getStuId() { return stuId; } public void setStuId(String stuId) { this.stuId = stuId; } //姓名屬性封裝 public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } //性別屬性封裝 public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } //電話屬性封裝 public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } //地址屬性封裝 public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } //年齡屬性封裝 public int getAge() { return age; } public void setAge(int age) { this.age = age; } //設定選修課程 public void setSelCourse(String[] cIds) { //cIds課程號陣列 001,002 selCourse=new SelectCourse[cIds.length]; for(int j=0;j<cIds.length;j++){ selCourse[j]= new SelectCourse(cIds[j]); } } //錄入選修課程成績 public void setSelCourseGrade(double[] grades) { //grades成績陣列 for(int j=0;j<grades.length;j++){ selCourse[j].grade= grades[j]; } } //計算學生各門課程的平均成績 double getAvg(){ double sum=0; for(int i=0;i<selCourse.length;i++){ sum=sum+selCourse[i].grade; } return sum/selCourse.length; } //計算學生各門課程的總和 double getSum(){ double sum=0; for(int i=0;i<selCourse.length;i++){ sum=sum+selCourse[i].grade; } return sum; } //內部類,用來記錄選修的課程及成績 class SelectCourse{ String courseId; double grade; SelectCourse(){ } SelectCourse(String courseId){ this.courseId=courseId; } SelectCourse(String courseId,double grade){ this.courseId=courseId; this.grade=grade; } } }
Teacher.java
public class Teacher { //設定Teacher類的屬性 private String teaId; //工號 private String teaName; //姓名 private String sex; //性別 private String tel; //電話 private String professor; //職稱 private int age; //年齡 TeachCourse teachCourse[]; //所授課程 //構造方法 Teacher(){ } Teacher(String teaId,String teaName){ this.teaId=teaId; this.teaName=teaName; } Teacher(String teaId,String teaName,String professor,int age){ this(teaId,teaName); //this的用法 this.sex=sex; this.tel=tel; this.professor=professor; //地址 this.age=age; } //工號屬性封裝 public String getTeaId() { return teaId; } public void setTeaId(String teaId) { this.teaId = teaId; } //姓名屬性封裝 public String getTeaName() { return teaName; } public void setTeaName(String teaName) { this.teaName = teaName; } //性別屬性封裝 public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } //電話屬性封裝 public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } //職稱屬性封裝 public String getProfessor() { return professor; } public void setProfessor(String professor) { this.professor = professor; } //年齡屬性封裝 public int getAge() { return age; } public void setAge(int age) { this.age = age; } //所授課程設定 public void setTeachCourse(String[] cIds) { teachCourse=new TeachCourse[cIds.length]; for(int j=0;j<cIds.length;j++){ teachCourse[j]= new TeachCourse(cIds[j]); } } //設定所授課程評價 public void setTeachEvaluate(String[] evaluates) { //grades成績陣列 for(int j=0;j<evaluates.length;j++){ teachCourse[j].evaluate= evaluates[j]; } } //內部類,教師所授課程 class TeachCourse{ String courseId; //課程編號 String evaluate; //課程評價 TeachCourse(String courseId){ this.courseId=courseId; } TeachCourse(String courseId,String evaluate){ this.courseId=courseId; this.evaluate=courseId; } } }
ps/測試資料
01,張三,男,13500043567,浙江杭州,21
02,李四,13099872371,浙江溫州,21
03,王五,13790972431,浙江金華,21
04,趙六,女,13190345445,浙江台州,21
05,孫七,13943298712,浙江湖州,21
001,Java程式設計,6
002,網頁設計,3.5
003,AppInventor,2
01,李老師,講師,39
02,楊老師,38
03,高老師,副教授,39
04,趙老師,56
05,孫老師,教授,47
到此這篇關於Java 實現簡易教務管理系統的程式碼的文章就介紹到這了,更多相關Java教務管理系統內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!