服务器之家

服务器之家 > 正文

Java 实现简易教务管理系统的代码

时间:2020-07-29 00:44     来源/作者:nochiller

Main.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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;
            }
        }
    }
}

Student.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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

到此这篇关于Java 实现简易教务管理系统的代码的文章就介绍到这了,更多相关Java教务管理系统内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/nochiller/article/details/107603178

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-05-20
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意 2019-07-07
返回顶部