用java.设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。文字步骤详细。
时间: 2023-10-20 14:05:28 浏览: 72
好的,我可以为您提供一个简单的学校人事管理系统的设计,使用Java语言实现。
1. 首先,我们需要设计一个Person类,作为教师和学生类的父类,其中包含编号、姓名、性别和出生日期等共有属性,代码如下:
```
public class Person {
private int id;
private String name;
private String gender;
private String birthdate;
public Person(int id, String name, String gender, String birthdate) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthdate = birthdate;
}
// getter and setter methods
}
```
2. 接下来,我们需要设计一个Teacher类,继承自Person类,包括部门、职称和工资等属性,代码如下:
```
public class Teacher extends Person {
private String department;
private String title;
private double salary;
public Teacher(int id, String name, String gender, String birthdate, String department, String title, double salary) {
super(id, name, gender, birthdate);
this.department = department;
this.title = title;
this.salary = salary;
}
// getter and setter methods
}
```
3. 再设计一个Student类,同样继承自Person类,包括高考分数、专业和班级等属性,代码如下:
```
public class Student extends Person {
private int score;
private String field;
private String className;
public Student(int id, String name, String gender, String birthdate, int score, String field, String className) {
super(id, name, gender, birthdate);
this.score = score;
this.field = field;
this.className = className;
}
// getter and setter methods
}
```
4. 接下来,我们需要设计一个管理类,用于实现教师和学生信息的添加、删除、修改和查询功能,代码如下:
```
import java.util.ArrayList;
public class Management {
private ArrayList<Teacher> teacherList;
private ArrayList<Student> studentList;
public Management() {
teacherList = new ArrayList<Teacher>();
studentList = new ArrayList<Student>();
}
// 添加教师
public void addTeacher(Teacher teacher) {
teacherList.add(teacher);
}
// 删除教师
public void deleteTeacher(int id) {
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
teacherList.remove(teacher);
break;
}
}
}
// 修改教师信息
public void modifyTeacher(int id, String department, String title, double salary) {
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
teacher.setDepartment(department);
teacher.setTitle(title);
teacher.setSalary(salary);
break;
}
}
}
// 查询教师信息
public void queryTeacher(int id) {
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
System.out.println("编号:" + teacher.getId());
System.out.println("姓名:" + teacher.getName());
System.out.println("性别:" + teacher.getGender());
System.out.println("出生日期:" + teacher.getBirthdate());
System.out.println("部门:" + teacher.getDepartment());
System.out.println("职称:" + teacher.getTitle());
System.out.println("工资:" + teacher.getSalary());
break;
}
}
}
// 添加学生
public void addStudent(Student student) {
studentList.add(student);
}
// 删除学生
public void deleteStudent(int id) {
for (Student student : studentList) {
if (student.getId() == id) {
studentList.remove(student);
break;
}
}
}
// 修改学生信息
public void modifyStudent(int id, int score, String field, String className) {
for (Student student : studentList) {
if (student.getId() == id) {
student.setScore(score);
student.setField(field);
student.setClassName(className);
break;
}
}
}
// 查询学生信息
public void queryStudent(int id) {
for (Student student : studentList) {
if (student.getId() == id) {
System.out.println("编号:" + student.getId());
System.out.println("姓名:" + student.getName());
System.out.println("性别:" + student.getGender());
System.out.println("出生日期:" + student.getBirthdate());
System.out.println("高考分数:" + student.getScore());
System.out.println("专业:" + student.getField());
System.out.println("班级:" + student.getClassName());
break;
}
}
}
}
```
5. 最后,我们可以在主方法中测试管理类的功能:
```
public static void main(String[] args) {
Management management = new Management();
// 添加教师
Teacher teacher1 = new Teacher(1, "Tom", "male", "1990-01-01", "Math", "Professor", 10000.0);
Teacher teacher2 = new Teacher(2, "Jerry", "male", "1995-01-01", "English", "Lecturer", 8000.0);
management.addTeacher(teacher1);
management.addTeacher(teacher2);
// 添加学生
Student student1 = new Student(1001, "Alice", "female", "2000-01-01", 600, "Math", "Class A");
Student student2 = new Student(1002, "Bob", "male", "2001-01-01", 550, "English", "Class B");
management.addStudent(student1);
management.addStudent(student2);
// 修改教师信息
management.modifyTeacher(1, "Physics", "Associate Professor", 9000.0);
// 查询学生信息
management.queryStudent(1001);
// 删除教师
management.deleteTeacher(2);
}
```
以上就是一个简单的学校人事管理系统的设计和实现,您可以根据实际需要进行修改和完善。
阅读全文