初步功能如上图,后对其进行了优化,使其系统可以实现的功能更加齐全,完善。(文末给出源代码链接)
涉及到的功能如下图:
话不多说,先上代码:
一、Student类
package 学生评教管理系统; import java.io.Serializable; public class Student implements Serializable { private int sid; //学号 private String name; //姓名 private int age; //年龄 private String address; //住址 public Student() { super(); } public Student(int sid, String name, int age, String address) { super(); this.sid = sid; this.name = name; this.age = age; this.address = address; } public int getSid() { return sid; } public void setSid(int sid) { this.sid = sid; } 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 getAddress() { return address; } public void setAddress(String address) { this.address = address; } } 二、Teac
二、Teacher类
package 学生评教管理系统; public class Teacher { //设置Teacher类的属性 private String teaId; //工号 private String teaName; //姓名 private String sex; //性别 private String tel; //电话 private String professor; //职称 private int age; //年龄 String 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 String[cIds.length]; for (int j = 0; j < cIds.length; j++) { teachCourse[j] = cIds[j]; } } }
三、course类
package 学生评教管理系统; 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; } }
四、方法大类
package 学生评教管理系统; import java.util.ArrayList; import java.util.Scanner; public class Operator { Scanner scan; Operator() { scan = new Scanner(System.in); } //查询学生所有信息 public static void showAllStudent(ArrayList<Student> list) { //思路: 遍历集合,获得每一个学生对象,再输出学生对象的信息 System.out.println("学号\t\t\t姓名\t\t\t年龄\t\t住址"); for (Student stu : list) { System.out.println(stu.getSid() + "\t\t" + stu.getName() + "\t\t" + stu.getAge() + "\t\t" + stu.getAddress()); } } //添加学生 public static void addStudents(ArrayList<Student> list) { Scanner sc = new Scanner(System.in); System.out.println("请输入学号:"); int sid = sc.nextInt(); System.out.println("请输入姓名:"); String name = sc.next(); System.out.println("请输入年龄:"); int age = sc.nextInt(); System.out.println("请输入住址:"); String address = sc.next(); //2. 将学生的信息包装到Student Bean中 Student stu = new Student(sid, name, age, address); //3. 将学生这个对象保存到集合中 list.add(stu); System.out.println("添加成功!"); } //修改学生 public static void reviseStudent(ArrayList<Student> list) { // TODO Auto-generated method stub //1. 判断集合中有没有学生信息 Scanner sc = new Scanner(System.in); if (list.size() == 0) { System.out.println("当前没有学生信息"); return; //return直接跳出当前语句,不会执行下面的语句 } //2. 输入要修改的学生学号 System.out.println("请输入您想修改的学生学号:"); int id = sc.nextInt(); //3. 判断输入的id是否在list集合中,如果在,则执行一系列的代码,如果不在,直接跳出 boolean flag = false; for (int i = 0; i < list.size(); i++) { if (list.get(i).getSid() == id) { flag = true; //4. 提示用户输入新的学生信息(学号、姓名、年龄、住址) System.out.println("请输入新的学号:"); int sidNew = sc.nextInt(); System.out.println("请输入新的姓名:"); String nameNew = sc.next(); System.out.println("请输入新的年龄:"); int ageNew = sc.nextInt(); System.out.println("请输入新的住址:"); String addressNew = sc.next(); //5. 将接受到的学生的信息重新包装到Student Bean中 Student stu = new Student(sidNew, nameNew, ageNew, addressNew); //6. 将集合进行修改 list.set(i, stu); System.out.println("修改成功!"); break; } } if (flag == false) { System.out.println("没有找到该学生,请重新输入:"); } } //删除学生 public static void delStudent(ArrayList<Student> list) { //1. 判断集合中有没有学生信息 Scanner sc = new Scanner(System.in); if (list.size() == 0) { System.out.println("当前没有学生信息"); return; //return直接跳出当前语句,不会执行下面的语句 } //2. 输入要删除的学生的学号 System.out.println("请输入您想要删除的学生学号:"); int id = sc.nextInt(); //3. 判断输入的id是否在list集合中,如果在,则执行一系列的代码,如果不在,直接跳出 boolean flag = false; for (int i = 0; i < list.size(); i++) { if (list.get(i).getSid() == id) { flag = true; list.remove(i); System.out.println("删除成功!"); return; //break结束当前语句,下面的代码会继续执行 } } if (flag == false) { System.out.println("未找到您想要删除的学生信息,请重新输入"); } } //录入课程 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 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; System.out.println("删除成功!"); } } } //录入教师 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 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 showCourses(Teacher[] teachers, Course[] courses) { System.out.println("教师与课程号的对应关系如下:"); for (int i = 0; i < teachers.length; i++) { if (teachers[i].teachCourse.length > 0) { for (int j = 0; j < teachers[i].teachCourse.length; j++) { System.out.println("课程号:" + teachers[i].teachCourse[j] + "\t" + "课程名称:" + courses[Integer.parseInt(teachers[i].teachCourse[j]) - 1].getCourseName() + "\t教师工号:" + teachers[i].getTeaId() + "\t教师姓名:" + teachers[i].getTeaName()); } } } } //学生登录 public static boolean inputEvaluate(int studentId, int passworld, ArrayList<Student> list) { Scanner scans = new Scanner(System.in); boolean flag = false; for (int i = 0; i < list.size(); i++) { if (list.get(i).getSid() == studentId && passworld == 123456) { System.out.println("登录成功!"); flag = true; break; } else { flag = false; } } return flag; } //授课评价 public void evaluate(Teacher[] teachers) { Scanner input = new Scanner(System.in); for (int i = 0; i < teachers.length; i++) { System.out.println("请输入对第" + (i + 1) + "位老师的评价:"); String pingjia = input.next(); System.out.println("学生对第" + (i + 1) + "位老师的评价:" + pingjia); } } }
五、Main方法
package 学生评教管理系统; import java.util.ArrayList; import java.util.Scanner; import static 学生评教管理系统.Operator.inputEvaluate; public class Main { public static void main(String[] args) { ArrayList<Student> list = new ArrayList<Student>(); System.out.println("\t\t教师授课评教系统"); System.out.println("1、查询所有学生列表\t2、添加学生\t3、修改学生\t4、删除操作\t5、录入课程\t6、显示课程\t7、删除课程\t8、录入教师" + "\t9、显示教师\t10、教师排课\t11、查询教师与课程号的对应信息\t12、学生登录并授课评价\t13、退出"); Student[] students = null; Course courses[] = null; Teacher teachers[] = null; Student student[] = null; Operator operator = new Operator(); Scanner scan = new Scanner(System.in); itcase: while (true) { //显示系统主菜单 System.out.println("请选择您的功能:"); int choice = scan.nextInt();// 接收用户的选择 switch (choice) { case 1: // 输入学生信息 //执行查询所有学生列表的操作 operator.showAllStudent(list); break; case 2: //添加学生 operator.addStudents(list); break; case 3: //修改学生 operator.reviseStudent(list); break; case 4: //删除学生 operator.delStudent(list); break; case 5://录入课程 System.out.println("请输入课程数:"); int n = scan.nextInt(); courses = new Course[n]; operator.addCourses(courses); break; case 6: // 显示课程 operator.displayCourses(courses); break; case 7://删除课程 operator.delCourses(courses); break; case 8: // 录入教师 System.out.println("请输入教师数:"); n = scan.nextInt(); teachers = new Teacher[n]; operator.addTeachers(teachers); break; case 9:// 显示教师 operator.displayTeachers(teachers); break; case 10:// 教师排课 operator.assignTeachCourses(teachers, courses); break; case 11://查询教师与课程号的对应信息 operator.showCourses(teachers, courses); break; case 12:// 学生登录并授课评价 Scanner scanf = new Scanner(System.in); System.out.println("请输入您的学号:"); int studentId = scanf.nextInt(); System.out.println("请输入您的密码:"); int passworld = scanf.nextInt(); if (inputEvaluate(studentId, passworld, list)) { System.out.println("您已经可以对老师进行评教!"); operator.evaluate(teachers); } else { System.out.println("学号或密码不匹配,登录错误!"); } break; case 13:// 退出 System.out.println("退出学生评教管理系统!"); break itcase; default://输入非选择项 System.out.println("非法命令!"); } } } }
六、测试
第十个方法(教师排课):实现这一功能需将课程,教师全部录入后,便可实现自由给老师排课的功能
第十一个方法(查询教师与课程号的对应信息):同理
第十二个方法(学生登录并授课评价):登录账号为学生学号,密码为统一方便设置为:123456
注:在其添加学生,教师,课程等信息时,注意将每位元素以英文输入法下的逗号隔开(",")不同学生,教师,课程信息以回车换行进行输入。具体如下图:
七、对于本程序,个人能想到的功能已经进行了实现,可能或许会有些许漏洞(本人测试没有发现的)还请各位大佬给予指出,如发现可以优化的地方还请多多指教。
下载链接:
https://download.csdn.net/download/m0_54925305/84988840