1.用Java设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。
时间: 2023-07-04 10:03:24 浏览: 139
好的,我可以为你提供一个简单的学校人事管理系统的设计思路和代码实现。
首先,我们需要定义两个类:Teacher(教师)和Student(学生),它们都继承自一个基类Person(人)。
Person 类的属性包括编号(id)、姓名(name)、性别(gender)和出生日期(birthday),同时还需要提供相应的 getter 和 setter 方法。
```java
public class Person {
private int id;
private String name;
private String gender;
private Date birthday;
public void setId(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getGender() {
return this.gender;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Date getBirthday() {
return this.birthday;
}
}
```
Teacher 类继承自 Person 类,并增加部门(department)、职称(title)和工资(salary)属性,同样需要提供相应的 getter 和 setter 方法:
```java
public class Teacher extends Person {
private String department;
private String title;
private double salary;
public void setDepartment(String department) {
this.department = department;
}
public String getDepartment() {
return this.department;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getSalary() {
return this.salary;
}
}
```
Student 类同样继承自 Person 类,但增加了高考分数(score)、专业(field)和班级(className)属性:
```java
public class Student extends Person {
private int score;
private String field;
private String className;
public void setScore(int score) {
this.score = score;
}
public int getScore() {
return this.score;
}
public void setField(String field) {
this.field = field;
}
public String getField() {
return this.field;
}
public void setClassName(String className) {
this.className = className;
}
public String getClassName() {
return this.className;
}
}
```
接下来,我们需要定义一个管理系统类(ManagementSystem),用于管理教师和学生的信息。在该类中,我们可以使用 ArrayList 来存储教师和学生的信息,同时提供添加、删除、修改和查询等基本操作。
```java
import java.util.ArrayList;
public class ManagementSystem {
private ArrayList<Teacher> teachers;
private ArrayList<Student> students;
public ManagementSystem() {
teachers = new ArrayList<>();
students = new ArrayList<>();
}
// 添加教师
public void addTeacher(Teacher teacher) {
teachers.add(teacher);
}
// 添加学生
public void addStudent(Student student) {
students.add(student);
}
// 删除教师
public void removeTeacher(int id) {
for (Teacher teacher : teachers) {
if (teacher.getId() == id) {
teachers.remove(teacher);
return;
}
}
}
// 删除学生
public void removeStudent(int id) {
for (Student student : students) {
if (student.getId() == id) {
students.remove(student);
return;
}
}
}
// 修改教师信息
public void updateTeacher(Teacher teacher) {
for (int i = 0; i < teachers.size(); i++) {
if (teachers.get(i).getId() == teacher.getId()) {
teachers.set(i, teacher);
return;
}
}
}
// 修改学生信息
public void updateStudent(Student student) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId() == student.getId()) {
students.set(i, student);
return;
}
}
}
// 查询教师信息
public Teacher queryTeacher(int id) {
for (Teacher teacher : teachers) {
if (teacher.getId() == id) {
return teacher;
}
}
return null;
}
// 查询学生信息
public Student queryStudent(int id) {
for (Student student : students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
}
```
至此,我们已经完成了一个简单的学校人事管理系统的设计和实现。在实际使用中,我们可以通过调用 ManagementSystem 类中提供的方法来添加、删除、修改和查询教师和学生的信息。
希望这个简单的示例对你有所帮助!
阅读全文