关于java:Java-简易教务管理系统

34次阅读

共计 9541 个字符,预计需要花费 24 分钟才能阅读完成。

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[1],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],sInfor[1],sInfor[2],sInfor[3],sInfor[4],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, 课程号 2,......");        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;            }        }    }}

外汇 MT4 教程 https://www.kaifx.cn/mt4.html

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 sex,String tel,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, 李老师, 男,13500043567, 讲师,39
02, 杨老师, 女,13099872371, 讲师,38
03, 高老师, 女,13790972431, 副教授,39
04, 赵老师, 男,13190345445, 副教授,56
05, 孙老师, 女,13943298712, 传授,47

正文完
 0