用java设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。
时间: 2023-10-20 10:14:47 浏览: 95
好的,以下是一个简单的学校人事管理系统的Java代码实现:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class SchoolManagementSystem {
private ArrayList<Student> students;
private ArrayList<Teacher> teachers;
public SchoolManagementSystem() {
students = new ArrayList<>();
teachers = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void addTeacher(Teacher teacher) {
teachers.add(teacher);
}
public void removeStudent(int id) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId() == id) {
students.remove(i);
return;
}
}
System.out.println("学生不存在!");
}
public void removeTeacher(int id) {
for (int i = 0; i < teachers.size(); i++) {
if (teachers.get(i).getId() == id) {
teachers.remove(i);
return;
}
}
System.out.println("教师不存在!");
}
public void updateStudent(int id, Student newStudent) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId() == id) {
students.set(i, newStudent);
return;
}
}
System.out.println("学生不存在!");
}
public void updateTeacher(int id, Teacher newTeacher) {
for (int i = 0; i < teachers.size(); i++) {
if (teachers.get(i).getId() == id) {
teachers.set(i, newTeacher);
return;
}
}
System.out.println("教师不存在!");
}
public void queryStudent(int id) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId() == id) {
System.out.println(students.get(i));
return;
}
}
System.out.println("学生不存在!");
}
public void queryTeacher(int id) {
for (int i = 0; i < teachers.size(); i++) {
if (teachers.get(i).getId() == id) {
System.out.println(teachers.get(i));
return;
}
}
System.out.println("教师不存在!");
}
public static void main(String[] args) {
SchoolManagementSystem sms = new SchoolManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:1.添加学生 2.添加教师 3.删除学生 4.删除教师 5.修改学生信息 6.修改教师信息 7.查询学生信息 8.查询教师信息 9.退出");
int operation = scanner.nextInt();
switch (operation) {
case 1:
System.out.println("请输入学生编号:");
int studentId = scanner.nextInt();
System.out.println("请输入学生姓名:");
String studentName = scanner.next();
System.out.println("请输入学生性别:");
String studentGender = scanner.next();
System.out.println("请输入学生出生日期:");
String studentBirthday = scanner.next();
System.out.println("请输入学生高考分数:");
int studentScore = scanner.nextInt();
System.out.println("请输入学生专业:");
String studentField = scanner.next();
System.out.println("请输入学生班级:");
String studentClass = scanner.next();
Student newStudent = new Student(studentId, studentName, studentGender, studentBirthday, studentScore, studentField, studentClass);
sms.addStudent(newStudent);
System.out.println("学生添加成功!");
break;
case 2:
System.out.println("请输入教师编号:");
int teacherId = scanner.nextInt();
System.out.println("请输入教师姓名:");
String teacherName = scanner.next();
System.out.println("请输入教师性别:");
String teacherGender = scanner.next();
System.out.println("请输入教师出生日期:");
String teacherBirthday = scanner.next();
System.out.println("请输入教师部门:");
String teacherDepartment = scanner.next();
System.out.println("请输入教师职称:");
String teacherTitle = scanner.next();
System.out.println("请输入教师工资:");
double teacherSalary = scanner.nextDouble();
Teacher newTeacher = new Teacher(teacherId, teacherName, teacherGender, teacherBirthday, teacherDepartment, teacherTitle, teacherSalary);
sms.addTeacher(newTeacher);
System.out.println("教师添加成功!");
break;
case 3:
System.out.println("请输入要删除的学生编号:");
int deleteStudentId = scanner.nextInt();
sms.removeStudent(deleteStudentId);
break;
case 4:
System.out.println("请输入要删除的教师编号:");
int deleteTeacherId = scanner.nextInt();
sms.removeTeacher(deleteTeacherId);
break;
case 5:
System.out.println("请输入要修改的学生编号:");
int updateStudentId = scanner.nextInt();
System.out.println("请输入学生姓名:");
String updateStudentName = scanner.next();
System.out.println("请输入学生性别:");
String updateStudentGender = scanner.next();
System.out.println("请输入学生出生日期:");
String updateStudentBirthday = scanner.next();
System.out.println("请输入学生高考分数:");
int updateStudentScore = scanner.nextInt();
System.out.println("请输入学生专业:");
String updateStudentField = scanner.next();
System.out.println("请输入学生班级:");
String updateStudentClass = scanner.next();
Student updatedStudent = new Student(updateStudentId, updateStudentName, updateStudentGender, updateStudentBirthday, updateStudentScore, updateStudentField, updateStudentClass);
sms.updateStudent(updateStudentId, updatedStudent);
break;
case 6:
System.out.println("请输入要修改的教师编号:");
int updateTeacherId = scanner.nextInt();
System.out.println("请输入教师姓名:");
String updateTeacherName = scanner.next();
System.out.println("请输入教师性别:");
String updateTeacherGender = scanner.next();
System.out.println("请输入教师出生日期:");
String updateTeacherBirthday = scanner.next();
System.out.println("请输入教师部门:");
String updateTeacherDepartment = scanner.next();
System.out.println("请输入教师职称:");
String updateTeacherTitle = scanner.next();
System.out.println("请输入教师工资:");
double updateTeacherSalary = scanner.nextDouble();
Teacher updatedTeacher = new Teacher(updateTeacherId, updateTeacherName, updateTeacherGender, updateTeacherBirthday, updateTeacherDepartment, updateTeacherTitle, updateTeacherSalary);
sms.updateTeacher(updateTeacherId, updatedTeacher);
break;
case 7:
System.out.println("请输入要查询的学生编号:");
int queryStudentId = scanner.nextInt();
sms.queryStudent(queryStudentId);
break;
case 8:
System.out.println("请输入要查询的教师编号:");
int queryTeacherId = scanner.nextInt();
sms.queryTeacher(queryTeacherId);
break;
case 9:
System.out.println("程序退出!");
System.exit(0);
default:
System.out.println("无效操作!");
break;
}
}
}
}
class Student {
private int id;
private String name;
private String gender;
private String birthday;
private int score;
private String field;
private String clazz;
public Student(int id, String name, String gender, String birthday, int score, String field, String clazz) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
this.score = score;
this.field = field;
this.clazz = clazz;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getBirthday() {
return birthday;
}
public int getScore() {
return score;
}
public String getField() {
return field;
}
public String getClazz() {
return clazz;
}
@Override
public String toString() {
return "学生信息:编号=" + id +
", 姓名='" + name + '\'' +
", 性别='" + gender + '\'' +
", 出生日期='" + birthday + '\'' +
", 高考分数=" + score +
", 专业='" + field + '\'' +
", 班级='" + clazz + '\'';
}
}
class Teacher {
private int id;
private String name;
private String gender;
private String birthday;
private String department;
private String title;
private double salary;
public Teacher(int id, String name, String gender, String birthday, String department, String title, double salary) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
this.department = department;
this.title = title;
this.salary = salary;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getBirthday() {
return birthday;
}
public String getDepartment() {
return department;
}
public String getTitle() {
return title;
}
public double getSalary() {
return salary;
}
@Override
public String toString() {
return "教师信息:编号=" + id +
", 姓名='" + name + '\'' +
", 性别='" + gender + '\'' +
", 出生日期='" + birthday + '\'' +
", 部门='" + department + '\'' +
", 职称='" + title + '\'' +
", 工资=" + salary;
}
}
```
系统界面如下:
```
请选择操作:1.添加学生 2.添加教师 3.删除学生 4.删除教师 5.修改学生信息 6.修改教师信息 7.查询学生信息 8.查询教师信息 9.退出
```
你可以根据提示进行相应的操作。
阅读全文