java.设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。
时间: 2023-10-20 21:10:58 浏览: 214
好的,这个学校人事管理系统可以使用面向对象的思想进行设计和实现。首先我们可以定义两个类:Teacher和Student,它们都包含编号、姓名、性别、出生日期这些共有的属性,并分别包含教师和学生特有的属性。
代码示例:
```java
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;
}
// getter和setter方法
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;
}
// 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 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 clazz; // 班级
// 构造函数
public Student(int id, String name, String gender, Date birthdate,
int score, String field, String clazz) {
super(id, name, gender, birthdate);
this.score = score;
this.field = field;
this.clazz = clazz;
}
// getter和setter方法
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 getClazz() {
return clazz;
}
public void setClazz(String clazz) {
this.clazz = clazz;
}
}
```
接下来,我们可以定义一个管理类SchoolManagementSystem,它包含一个教师列表和一个学生列表,以及对它们进行添加、删除、修改、查询的方法。
代码示例:
```java
import java.util.ArrayList;
import java.util.List;
public class SchoolManagementSystem {
private List<Teacher> teacherList; // 教师列表
private List<Student> studentList; // 学生列表
// 构造函数
public SchoolManagementSystem() {
this.teacherList = new ArrayList<Teacher>();
this.studentList = new ArrayList<Student>();
}
// 添加教师
public void addTeacher(Teacher teacher) {
teacherList.add(teacher);
}
// 删除教师
public void removeTeacher(int id) {
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
teacherList.remove(teacher);
break;
}
}
}
// 修改教师
public void updateTeacher(Teacher teacher) {
for (int i = 0; i < teacherList.size(); i++) {
if (teacherList.get(i).getId() == teacher.getId()) {
teacherList.set(i, teacher);
break;
}
}
}
// 查询教师
public Teacher queryTeacher(int id) {
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
return teacher;
}
}
return null;
}
// 添加学生
public void addStudent(Student student) {
studentList.add(student);
}
// 删除学生
public void removeStudent(int id) {
for (Student student : studentList) {
if (student.getId() == id) {
studentList.remove(student);
break;
}
}
}
// 修改学生
public void updateStudent(Student student) {
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId() == student.getId()) {
studentList.set(i, student);
break;
}
}
}
// 查询学生
public Student queryStudent(int id) {
for (Student student : studentList) {
if (student.getId() == id) {
return student;
}
}
return null;
}
}
```
这样,我们就完成了一个简单的学校人事管理系统,可以对教师和学生的基本信息进行添加、删除、修改、查询。当然,实际的系统还需要一些其他的功能,例如输入输出、数据存储等,这里就不做详细说明了。
阅读全文