用java设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。
时间: 2023-11-08 11:37:45 浏览: 398
好的,这是一个典型的java应用程序开发问题。我们可以使用面向对象编程的思想,设计一个学校人事管理系统。首先需要创建一个Person类来表示人员信息,然后创建Teacher和Student类来继承Person类,分别表示教师和学生信息。以下是一个简单的实现:
public class Person {
private int id;
private String name;
private String gender;
private Date birthdate;
public Person(int id, String name, String gender, Date birthdate) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthdate = birthdate;
}
public int getId() {
return id;
}
public void setId(int 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 Date getBirthdate() {
return birthdate;
}
public void setBirthdate(Date birthdate) {
this.birthdate = birthdate;
}
}
public class Teacher extends Person {
private String department;
private String title;
private int salary;
public Teacher(int id, String name, String gender, Date birthdate, String department, String title, int salary) {
super(id, name, gender, birthdate);
this.department = department;
this.title = title;
this.salary = salary;
}
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 int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
public class Student extends Person {
private int score;
private String field;
private String className;
public Student(int id, String name, String gender, Date birthdate, int score, String field, String className) {
super(id, name, gender, birthdate);
this.score = score;
this.field = field;
this.className = className;
}
public int getScore() {
return score;
}
public void setScore(int 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类来实现我们的需求,包括添加、删除、修改和查询学生和教师信息的方法。
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(int id) {
this.teachers.removeIf(t -> t.getId() == id);
}
public void updateTeacher(Teacher teacher) {
Teacher existingTeacher = this.teachers.stream()
.filter(t -> t.getId() == teacher.getId())
.findFirst()
.orElse(null);
if (existingTeacher != null) {
existingTeacher.setName(teacher.getName());
existingTeacher.setGender(teacher.getGender());
existingTeacher.setBirthdate(teacher.getBirthdate());
existingTeacher.setDepartment(teacher.getDepartment());
existingTeacher.setTitle(teacher.getTitle());
existingTeacher.setSalary(teacher.getSalary());
}
}
public List<Teacher> searchTeacher(String keyword) {
return this.teachers.stream()
.filter(t -> t.getName().contains(keyword)
|| t.getDepartment().contains(keyword))
.collect(Collectors.toList());
}
public void addStudent(Student student) {
this.students.add(student);
}
public void deleteStudent(int id) {
this.students.removeIf(s -> s.getId() == id);
}
public void updateStudent(Student student) {
Student existingStudent = this.students.stream()
.filter(s -> s.getId() == student.getId())
.findFirst()
.orElse(null);
if (existingStudent != null) {
existingStudent.setName(student.getName());
existingStudent.setGender(student.getGender());
existingStudent.setBirthdate(student.getBirthdate());
existingStudent.setScore(student.getScore());
existingStudent.setField(student.getField());
existingStudent.setClassName(student.getClassName());
}
}
public List<Student> searchStudent(String keyword) {
return this.students.stream()
.filter(s -> s.getName().contains(keyword)
|| s.getField().contains(keyword))
.collect(Collectors.toList());
}
}
这样,我们就完成了一个基本的学校人事管理系统。当然,这只是一个简单的实现,实际应用中可能还需要更多的功能和优化。
阅读全文