用java语言设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。
时间: 2023-10-20 22:20:10 浏览: 113
好的,这是一个比较典型的CRUD操作,我们可以使用Java的面向对象编程语言来实现这个简单的学校人事管理系统。
首先,我们需要定义一个基本的人员信息类Person,包含编号、姓名、性别和出生日期等属性:
```java
public class Person {
private String id; // 编号
private String name; // 姓名
private String gender; // 性别
private String birthday; // 出生日期
// 构造函数
public Person(String id, String name, String gender, String birthday) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
}
// getter和setter方法
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
}
```
接着,我们定义教师类Teacher和学生类Student,继承自Person类,并添加各自独有的属性:
```java
public class Teacher extends Person {
private String department; // 部门
private String title; // 职称
private double salary; // 工资
// 构造函数
public Teacher(String id, String name, String gender, String birthday, String department, String title, double salary) {
super(id, name, gender, birthday);
this.department = department;
this.title = title;
this.salary = salary;
}
// getter和setter方法
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
public class Student extends Person {
private double score; // 高考分数
private String field; // 专业
private String className; // 班级
// 构造函数
public Student(String id, String name, String gender, String birthday, double score, String field, String className) {
super(id, name, gender, birthday);
this.score = score;
this.field = field;
this.className = className;
}
// getter和setter方法
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}
```
现在,我们可以定义一个管理系统类SchoolManagementSystem,用来实现教师和学生信息的添加、删除、修改和查询功能:
```java
import java.util.ArrayList;
import java.util.List;
public class SchoolManagementSystem {
private List<Teacher> teachers; // 教师列表
private List<Student> students; // 学生列表
// 构造函数
public SchoolManagementSystem() {
this.teachers = new ArrayList<>();
this.students = new ArrayList<>();
}
// 添加教师信息
public void addTeacher(Teacher teacher) {
this.teachers.add(teacher);
}
// 删除教师信息
public void deleteTeacher(String id) {
Teacher teacher = findTeacherById(id);
if (teacher != null) {
this.teachers.remove(teacher);
}
}
// 修改教师信息
public void updateTeacher(Teacher teacher) {
Teacher oldTeacher = findTeacherById(teacher.getId());
if (oldTeacher != null) {
oldTeacher.setName(teacher.getName());
oldTeacher.setGender(teacher.getGender());
oldTeacher.setBirthday(teacher.getBirthday());
oldTeacher.setDepartment(teacher.getDepartment());
oldTeacher.setTitle(teacher.getTitle());
oldTeacher.setSalary(teacher.getSalary());
}
}
// 查询教师信息
public List<Teacher> findTeachers(String keyword) {
List<Teacher> result = new ArrayList<>();
for (Teacher teacher : this.teachers) {
if (teacher.getName().contains(keyword) || teacher.getId().equals(keyword)) {
result.add(teacher);
}
}
return result;
}
// 根据id查找教师
private Teacher findTeacherById(String id) {
for (Teacher teacher : this.teachers) {
if (teacher.getId().equals(id)) {
return teacher;
}
}
return null;
}
// 添加学生信息
public void addStudent(Student student) {
this.students.add(student);
}
// 删除学生信息
public void deleteStudent(String id) {
Student student = findStudentById(id);
if (student != null) {
this.students.remove(student);
}
}
// 修改学生信息
public void updateStudent(Student student) {
Student oldStudent = findStudentById(student.getId());
if (oldStudent != null) {
oldStudent.setName(student.getName());
oldStudent.setGender(student.getGender());
oldStudent.setBirthday(student.getBirthday());
oldStudent.setScore(student.getScore());
oldStudent.setField(student.getField());
oldStudent.setClassName(student.getClassName());
}
}
// 查询学生信息
public List<Student> findStudents(String keyword) {
List<Student> result = new ArrayList<>();
for (Student student : this.students) {
if (student.getName().contains(keyword) || student.getId().equals(keyword)) {
result.add(student);
}
}
return result;
}
// 根据id查找学生
private Student findStudentById(String id) {
for (Student student : this.students) {
if (student.getId().equals(id)) {
return student;
}
}
return null;
}
}
```
现在我们已经定义了一个简单的学校人事管理系统,可以进行教师和学生信息的添加、删除、修改和查询操作。当然,这只是一个最基本的实现方式,还可以根据实际需求进行更多的功能扩展和优化。
阅读全文