用java.设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、班级等。文字描述清楚,代码注释详细,操作步骤清楚详细。
时间: 2023-10-20 14:08:45 浏览: 73
基于JAVA的学生信息管理系统.rar
5星 · 资源好评率100%
这是一个比较完整的学校人事管理系统,包括教师和学生信息的添加、删除、修改、查询等功能。下面是详细的代码实现和操作步骤。
1. 教师信息类
```
public class Teacher {
private String id; //编号
private String name; //姓名
private String gender; //性别
private String birthday; //出生日期
private String department; //部门
private String title; //职称
private double salary; //工资
public Teacher(String 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 String getId() {
return id;
}
public void setId(String 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 String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
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 double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "教师信息{" +
"编号='" + id + '\'' +
", 姓名='" + name + '\'' +
", 性别='" + gender + '\'' +
", 出生日期='" + birthday + '\'' +
", 部门='" + department + '\'' +
", 职称='" + title + '\'' +
", 工资=" + salary +
'}';
}
}
```
2. 学生信息类
```
public class Student {
private String id; //编号
private String name; //姓名
private String gender; //性别
private String birthday; //出生日期
private int score; //高考分数
private String field; //专业
private String cls; //班级
public Student(String id, String name, String gender, String birthday, int score, String field, String cls) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
this.score = score;
this.field = field;
this.cls = cls;
}
public String getId() {
return id;
}
public void setId(String 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 String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
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 getCls() {
return cls;
}
public void setCls(String cls) {
this.cls = cls;
}
@Override
public String toString() {
return "学生信息{" +
"编号='" + id + '\'' +
", 姓名='" + name + '\'' +
", 性别='" + gender + '\'' +
", 出生日期='" + birthday + '\'' +
", 高考分数=" + score +
", 专业='" + field + '\'' +
", 班级='" + cls + '\'' +
'}';
}
}
```
3. 数据库类
```
import java.util.ArrayList;
import java.util.List;
public class Database {
private List<Teacher> teachers; //教师信息列表
private List<Student> students; //学生信息列表
public Database() {
teachers = new ArrayList<>();
students = new ArrayList<>();
}
//添加教师信息
public void addTeacher(Teacher teacher) {
teachers.add(teacher);
}
//删除教师信息
public void deleteTeacher(String id) {
for (Teacher teacher : teachers) {
if (teacher.getId().equals(id)) {
teachers.remove(teacher);
return;
}
}
}
//修改教师信息
public void modifyTeacher(Teacher teacher) {
for (int i = 0; i < teachers.size(); i++) {
if (teachers.get(i).getId().equals(teacher.getId())) {
teachers.set(i, teacher);
return;
}
}
}
//查询教师信息
public List<Teacher> queryTeacher(String key) {
List<Teacher> result = new ArrayList<>();
for (Teacher teacher : teachers) {
if (teacher.getId().equals(key) || teacher.getName().equals(key)) {
result.add(teacher);
}
}
return result;
}
//添加学生信息
public void addStudent(Student student) {
students.add(student);
}
//删除学生信息
public void deleteStudent(String id) {
for (Student student : students) {
if (student.getId().equals(id)) {
students.remove(student);
return;
}
}
}
//修改学生信息
public void modifyStudent(Student student) {
for (int i = 0; i < students.size(); i++) {
if (students.get(i).getId().equals(student.getId())) {
students.set(i, student);
return;
}
}
}
//查询学生信息
public List<Student> queryStudent(String key) {
List<Student> result = new ArrayList<>();
for (Student student : students) {
if (student.getId().equals(key) || student.getName().equals(key)) {
result.add(student);
}
}
return result;
}
//打印教师信息列表
public void printTeachers() {
for (Teacher teacher : teachers) {
System.out.println(teacher);
}
}
//打印学生信息列表
public void printStudents() {
for (Student student : students) {
System.out.println(student);
}
}
}
```
4. 主程序类
```
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Database database = new Database();
while (true) {
System.out.println("请选择操作:");
System.out.println("1.添加教师信息");
System.out.println("2.删除教师信息");
System.out.println("3.修改教师信息");
System.out.println("4.查询教师信息");
System.out.println("5.添加学生信息");
System.out.println("6.删除学生信息");
System.out.println("7.修改学生信息");
System.out.println("8.查询学生信息");
System.out.println("9.打印教师信息列表");
System.out.println("10.打印学生信息列表");
System.out.println("0.退出程序");
int choice = scanner.nextInt();
switch (choice) {
case 1: //添加教师信息
System.out.println("请输入教师编号:");
String tid = scanner.next();
System.out.println("请输入教师姓名:");
String tname = scanner.next();
System.out.println("请输入教师性别:");
String tgender = scanner.next();
System.out.println("请输入教师出生日期:");
String tbirthday = scanner.next();
System.out.println("请输入教师部门:");
String tdepartment = scanner.next();
System.out.println("请输入教师职称:");
String ttitle = scanner.next();
System.out.println("请输入教师工资:");
double tsalary = scanner.nextDouble();
Teacher teacher = new Teacher(tid, tname, tgender, tbirthday, tdepartment, ttitle, tsalary);
database.addTeacher(teacher);
System.out.println("添加教师信息成功!");
break;
case 2: //删除教师信息
System.out.println("请输入教师编号:");
String did = scanner.next();
database.deleteTeacher(did);
System.out.println("删除教师信息成功!");
break;
case 3: //修改教师信息
System.out.println("请输入教师编号:");
String mid = scanner.next();
List<Teacher> mlist = database.queryTeacher(mid);
if (mlist.isEmpty()) {
System.out.println("没有找到该教师信息!");
} else {
Teacher modifyTeacher = mlist.get(0);
System.out.println("请输入修改后的教师信息:");
System.out.println("请输入教师姓名:");
String mname = scanner.next();
System.out.println("请输入教师性别:");
String mgender = scanner.next();
System.out.println("请输入教师出生日期:");
String mbirthday = scanner.next();
System.out.println("请输入教师部门:");
String mdepartment = scanner.next();
System.out.println("请输入教师职称:");
String mtitle = scanner.next();
System.out.println("请输入教师工资:");
double msalary = scanner.nextDouble();
modifyTeacher.setName(mname);
modifyTeacher.setGender(mgender);
modifyTeacher.setBirthday(mbirthday);
modifyTeacher.setDepartment(mdepartment);
modifyTeacher.setTitle(mtitle);
modifyTeacher.setSalary(msalary);
database.modifyTeacher(modifyTeacher);
System.out.println("修改教师信息成功!");
}
break;
case 4: //查询教师信息
System.out.println("请输入教师编号或姓名:");
String qkey = scanner.next();
List<Teacher> qlist = database.queryTeacher(qkey);
if (qlist.isEmpty()) {
System.out.println("没有找到相关教师信息!");
} else {
for (Teacher t : qlist) {
System.out.println(t);
}
}
break;
case 5: //添加学生信息
System.out.println("请输入学生编号:");
String sid = scanner.next();
System.out.println("请输入学生姓名:");
String sname = scanner.next();
System.out.println("请输入学生性别:");
String sgender = scanner.next();
System.out.println("请输入学生出生日期:");
String sbirthday = scanner.next();
System.out.println("请输入学生高考分数:");
int sscore = scanner.nextInt();
System.out.println("请输入学生专业:");
String sfield = scanner.next();
System.out.println("请输入学生班级:");
String scls = scanner.next();
Student student = new Student(sid, sname, sgender, sbirthday, sscore, sfield, scls);
database.addStudent(student);
System.out.println("添加学生信息成功!");
break;
case 6: //删除学生信息
System.out.println("请输入学生编号:");
String dsid = scanner.next();
database.deleteStudent(dsid);
System.out.println("删除学生信息成功!");
break;
case 7: //修改学生信息
System.out.println("请输入学生编号:");
String msid = scanner.next();
List<Student> mslist = database.queryStudent(msid);
if (mslist.isEmpty()) {
System.out.println("没有找到该学生信息!");
} else {
Student modifyStudent = mslist.get(0);
System.out.println("请输入修改后的学生信息:");
System.out.println("请输入学生姓名:");
String msname = scanner.next();
System.out.println("请输入学生性别:");
String msgender = scanner.next();
System.out.println("请输入学生出生日期:");
String msbirthday = scanner.next();
System.out.println("请输入学生高考分数:");
int msscore = scanner.nextInt();
System.out.println("请输入学生专业:");
String msfield = scanner.next();
System.out.println("请输入学生班级:");
String mscls = scanner.next();
modifyStudent.setName(msname);
modifyStudent.setGender(msgender);
modifyStudent.setBirthday(msbirthday);
modifyStudent.setScore(msscore);
modifyStudent.setField(msfield);
modifyStudent.setCls(mscls);
database.modifyStudent(modifyStudent);
System.out.println("修改学生信息成功!");
}
break;
case 8: //查询学生信息
System.out.println("请输入学生编号或姓名:");
String sqkey = scanner.next();
List<Student> sqlist = database.queryStudent(sqkey);
if (sqlist.isEmpty()) {
System.out.println("没有找到相关学生信息!");
} else {
for (Student s : sqlist) {
System.out.println(s);
}
}
break;
case 9: //打印教师信息列表
database.printTeachers();
break;
case 10: //打印学生信息列表
database.printStudents();
break;
case 0: //退出程序
System.out.println("感谢使用本系统,再见!");
System.exit(0);
default:
System.out.println("输入有误,请重新输入!");
}
}
}
}
```
5. 操作步骤
运行程序后,根据提示选择不同的操作。以下是一些操作的示例:
添加教师信息:
```
请选择操作:
1.添加教师信息
2.删除教师信息
3.修改教师信息
4.查询教师信息
5.添加学生信息
6.删除学生信息
7.修改学生信息
8.查询学生信息
9.打印教师信息列表
10.打印学生信息列表
0.退出程序
1
请输入教师编号:
001
请输入教师姓名:
张三
请输入教师性别:
男
请输入教师出生日期:
1980-01-01
请输入教师部门:
计算机科学与工程系
请输入教师职称:
副教授
请输入教师工资:
8000
添加教师信息成功!
```
删除教师信息:
```
请选择操作:
1.添加教师信息
2.删除教师信息
3.修改教师信息
4.查询教师信息
5.添加学生信息
6.删除学生信息
7.修改学生信息
8.查询学生信息
9.打印教师信息列表
10.打印学生信息列表
0.退出程序
2
请输入教师编号:
001
删除教师信息成功!
```
修改教师信息:
```
请选择操作:
1.添加教师信息
2.删除教师信息
3.修改教师信息
4.查询教师信息
5.添加学生信息
6.删除学生信息
7.修改学生信息
8.查询学生信息
9.打印教师信息列表
10.打印学生信息列表
0.退出程序
3
请输入教师编号:
001
请输入修改后的教师信息:
请输入教师姓名:
李四
请输入教师性别:
男
请输入教师出生日期:
1980-01-01
请输入教师部门:
计算机科学与工程系
请输入教师职称:
教授
请输入教师工资:
10000
修改教师信息成功!
```
查询教师信息:
```
请选择操作:
1.添加教师信息
2.删除教师信息
3.修改教师信息
4.查询教师信息
5.添加学生信息
6.删除学生信息
7.修改学生信息
8.查询学生信息
9.打印教师信息列表
10.打印学生信息列表
0.退出程序
4
请输入教师编号或姓名:
李四
教师信息{编号='001', 姓名='李四', 性别='男', 出生日期='1980-01-01', 部门='计算机科
阅读全文