写一个教务管理系统代码
时间: 2024-05-10 11:16:41 浏览: 79
这是一个 Java 语言编写的简单教务管理系统代码,包含学生、教师、课程、成绩等基本功能:
```java
import java.util.ArrayList;
import java.util.Scanner;
class Student {
private String id;
private String name;
private String gender;
private String major;
public Student(String id, String name, String gender, String major) {
this.id = id;
this.name = name;
this.gender = gender;
this.major = major;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
}
class Teacher {
private String id;
private String name;
private String gender;
private String title;
public Teacher(String id, String name, String gender, String title) {
this.id = id;
this.name = name;
this.gender = gender;
this.title = title;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
class Course {
private String id;
private String name;
private Teacher teacher;
public Course(String id, String name, Teacher teacher) {
this.id = id;
this.name = name;
this.teacher = teacher;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
}
class Score {
private Student student;
private Course course;
private double score;
public Score(Student student, Course course, double score) {
this.student = student;
this.course = course;
this.score = score;
}
public Student getStudent() {
return student;
}
public Course getCourse() {
return course;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
public class EduManagementSystem {
private ArrayList<Student> studentList = new ArrayList<>();
private ArrayList<Teacher> teacherList = new ArrayList<>();
private ArrayList<Course> courseList = new ArrayList<>();
private ArrayList<Score> scoreList = new ArrayList<>();
public void addStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生编号:");
String id = scanner.next();
System.out.print("请输入学生姓名:");
String name = scanner.next();
System.out.print("请输入学生性别:");
String gender = scanner.next();
System.out.print("请输入学生专业:");
String major = scanner.next();
Student student = new Student(id, name, gender, major);
studentList.add(student);
System.out.println("添加学生成功!");
}
public void addTeacher() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入教师编号:");
String id = scanner.next();
System.out.print("请输入教师姓名:");
String name = scanner.next();
System.out.print("请输入教师性别:");
String gender = scanner.next();
System.out.print("请输入教师职称:");
String title = scanner.next();
Teacher teacher = new Teacher(id, name, gender, title);
teacherList.add(teacher);
System.out.println("添加教师成功!");
}
public void addCourse() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入课程编号:");
String id = scanner.next();
System.out.print("请输入课程名称:");
String name = scanner.next();
System.out.print("请输入授课教师编号:");
String teacherId = scanner.next();
Teacher teacher = null;
for (int i = 0; i < teacherList.size(); i++) {
if (teacherList.get(i).getId().equals(teacherId)) {
teacher = teacherList.get(i);
break;
}
}
if (teacher == null) {
System.out.println("授课教师编号不存在!");
return;
}
Course course = new Course(id, name, teacher);
courseList.add(course);
System.out.println("添加课程成功!");
}
public void addScore() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生编号:");
String studentId = scanner.next();
Student student = null;
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(studentId)) {
student = studentList.get(i);
break;
}
}
if (student == null) {
System.out.println("学生编号不存在!");
return;
}
System.out.print("请输入课程编号:");
String courseId = scanner.next();
Course course = null;
for (int i = 0; i < courseList.size(); i++) {
if (courseList.get(i).getId().equals(courseId)) {
course = courseList.get(i);
break;
}
}
if (course == null) {
System.out.println("课程编号不存在!");
return;
}
System.out.print("请输入成绩:");
double score = scanner.nextDouble();
Score s = new Score(student, course, score);
scoreList.add(s);
System.out.println("添加成绩成功!");
}
public void queryScore() {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生编号:");
String studentId = scanner.next();
Student student = null;
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(studentId)) {
student = studentList.get(i);
break;
}
}
if (student == null) {
System.out.println("学生编号不存在!");
return;
}
for (int i = 0; i < scoreList.size(); i++) {
if (scoreList.get(i).getStudent().getId().equals(studentId)) {
System.out.println("课程编号:" + scoreList.get(i).getCourse().getId() +
" 课程名称:" + scoreList.get(i).getCourse().getName() +
" 成绩:" + scoreList.get(i).getScore());
}
}
}
public void start() {
Scanner scanner = new Scanner(System.in);
while (true) {
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("0. 退出系统");
System.out.print("请选择操作:");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
addTeacher();
break;
case 3:
addCourse();
break;
case 4:
addScore();
break;
case 5:
queryScore();
break;
case 0:
System.out.println("谢谢使用!");
System.exit(0);
default:
System.out.println("无效的选择!");
break;
}
}
}
public static void main(String[] args) {
EduManagementSystem system = new EduManagementSystem();
system.start();
}
}
```
这个系统主要包含了添加学生、教师、课程、成绩以及查询成绩等功能,可以根据实际需求进行扩展和改进。
阅读全文