1.设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。 java实现
时间: 2023-10-20 21:26:03 浏览: 171
以下是一个简单的学校人事管理系统的Java实现,包括教师和学生的基本信息的添加、删除、修改和查询功能。
Teacher.java
```
public class Teacher {
private int id;
private String name;
private String gender;
private String birthDate;
private String department;
private String jobTitle;
private int salary;
public Teacher(int id, String name, String gender, String birthDate, String department, String jobTitle, int salary) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.department = department;
this.jobTitle = jobTitle;
this.salary = salary;
}
// getter and setter methods for all fields
}
```
Student.java
```
public class Student {
private int id;
private String name;
private String gender;
private String birthDate;
private int entranceScore;
private String field;
private String className;
public Student(int id, String name, String gender, String birthDate, int entranceScore, String field, String className) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthDate = birthDate;
this.entranceScore = entranceScore;
this.field = field;
this.className = className;
}
// getter and setter methods for all fields
}
```
SchoolManager.java
```
import java.util.ArrayList;
import java.util.List;
public class SchoolManager {
private List<Teacher> teachers;
private List<Student> students;
public SchoolManager() {
this.teachers = new ArrayList<Teacher>();
this.students = new ArrayList<Student>();
}
// add a teacher
public void addTeacher(int id, String name, String gender, String birthDate, String department, String jobTitle, int salary) {
Teacher teacher = new Teacher(id, name, gender, birthDate, department, jobTitle, salary);
this.teachers.add(teacher);
}
// add a student
public void addStudent(int id, String name, String gender, String birthDate, int entranceScore, String field, String className) {
Student student = new Student(id, name, gender, birthDate, entranceScore, field, className);
this.students.add(student);
}
// delete a teacher by ID
public void deleteTeacher(int id) {
for (Teacher teacher : this.teachers) {
if (teacher.getId() == id) {
this.teachers.remove(teacher);
break;
}
}
}
// delete a student by ID
public void deleteStudent(int id) {
for (Student student : this.students) {
if (student.getId() == id) {
this.students.remove(student);
break;
}
}
}
// update the information of a teacher by ID
public void updateTeacher(int id, String name, String gender, String birthDate, String department, String jobTitle, int salary) {
for (Teacher teacher : this.teachers) {
if (teacher.getId() == id) {
teacher.setName(name);
teacher.setGender(gender);
teacher.setBirthDate(birthDate);
teacher.setDepartment(department);
teacher.setJobTitle(jobTitle);
teacher.setSalary(salary);
break;
}
}
}
// update the information of a student by ID
public void updateStudent(int id, String name, String gender, String birthDate, int entranceScore, String field, String className) {
for (Student student : this.students) {
if (student.getId() == id) {
student.setName(name);
student.setGender(gender);
student.setBirthDate(birthDate);
student.setEntranceScore(entranceScore);
student.setField(field);
student.setClassName(className);
break;
}
}
}
// search for a teacher by ID
public Teacher searchTeacher(int id) {
for (Teacher teacher : this.teachers) {
if (teacher.getId() == id) {
return teacher;
}
}
return null;
}
// search for a student by ID
public Student searchStudent(int id) {
for (Student student : this.students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
}
```
使用示例:
```
public class Main {
public static void main(String[] args) {
SchoolManager manager = new SchoolManager();
// add a teacher
manager.addTeacher(1, "John", "Male", "1990-01-01", "Mathematics", "Professor", 10000);
// add a student
manager.addStudent(1, "Amy", "Female", "2000-01-01", 600, "Computer Science", "Class A");
// update the information of a teacher
manager.updateTeacher(1, "John Smith", "Male", "1990-02-02", "Computer Science", "Associate Professor", 8000);
// search for a student by ID
Student student = manager.searchStudent(1);
System.out.println(student.getName() + " " + student.getEntranceScore());
// delete a teacher by ID
manager.deleteTeacher(1);
}
}
```
阅读全文