用JAVA设计一个简单的学校人事管理系统,管理教师和学生信息。实现教师与学生基本信息的添加、删除、修改、查询。其中编号、姓名、性别、出生日期为共有的,教师包括部门、职称、工资;学生包括高考分数、专业field、
时间: 2023-10-20 12:18:23 浏览: 189
基于JAVA的学生信息管理系统.rar
5星 · 资源好评率100%
班级。以下是一个简单的学校人事管理系统的JAVA代码实现:
```
import java.util.ArrayList;
import java.util.Scanner;
public class SchoolManagementSystem {
public static void main(String[] args) {
ArrayList<Teacher> teacherList = new ArrayList<>();
ArrayList<Student> studentList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
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. 退出程序");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addTeacher(teacherList, scanner);
break;
case 2:
deleteTeacher(teacherList, scanner);
break;
case 3:
modifyTeacher(teacherList, scanner);
break;
case 4:
queryTeacher(teacherList, scanner);
break;
case 5:
addStudent(studentList, scanner);
break;
case 6:
deleteStudent(studentList, scanner);
break;
case 7:
modifyStudent(studentList, scanner);
break;
case 8:
queryStudent(studentList, scanner);
break;
case 9:
System.out.println("程序已退出!");
System.exit(0);
break;
default:
System.out.println("输入错误,请重新输入!");
break;
}
}
}
private static void addTeacher(ArrayList<Teacher> teacherList, Scanner scanner) {
System.out.println("请输入教师编号:");
int id = scanner.nextInt();
System.out.println("请输入教师姓名:");
String name = scanner.next();
System.out.println("请输入教师性别:");
String gender = scanner.next();
System.out.println("请输入教师出生日期:");
String birthday = scanner.next();
System.out.println("请输入教师部门:");
String department = scanner.next();
System.out.println("请输入教师职称:");
String title = scanner.next();
System.out.println("请输入教师工资:");
double salary = scanner.nextDouble();
Teacher teacher = new Teacher(id, name, gender, birthday, department, title, salary);
teacherList.add(teacher);
System.out.println("教师信息已添加!");
}
private static void deleteTeacher(ArrayList<Teacher> teacherList, Scanner scanner) {
System.out.println("请输入要删除的教师编号:");
int id = scanner.nextInt();
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
teacherList.remove(teacher);
System.out.println("教师信息已删除!");
return;
}
}
System.out.println("未找到该教师!");
}
private static void modifyTeacher(ArrayList<Teacher> teacherList, Scanner scanner) {
System.out.println("请输入要修改的教师编号:");
int id = scanner.nextInt();
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
System.out.println("请输入新的教师姓名:");
String name = scanner.next();
System.out.println("请输入新的教师性别:");
String gender = scanner.next();
System.out.println("请输入新的教师出生日期:");
String birthday = scanner.next();
System.out.println("请输入新的教师部门:");
String department = scanner.next();
System.out.println("请输入新的教师职称:");
String title = scanner.next();
System.out.println("请输入新的教师工资:");
double salary = scanner.nextDouble();
teacher.setName(name);
teacher.setGender(gender);
teacher.setBirthday(birthday);
teacher.setDepartment(department);
teacher.setTitle(title);
teacher.setSalary(salary);
System.out.println("教师信息已修改!");
return;
}
}
System.out.println("未找到该教师!");
}
private static void queryTeacher(ArrayList<Teacher> teacherList, Scanner scanner) {
System.out.println("请输入要查询的教师编号:");
int id = scanner.nextInt();
for (Teacher teacher : teacherList) {
if (teacher.getId() == id) {
System.out.println(teacher.toString());
return;
}
}
System.out.println("未找到该教师!");
}
private static void addStudent(ArrayList<Student> studentList, Scanner scanner) {
System.out.println("请输入学生编号:");
int id = scanner.nextInt();
System.out.println("请输入学生姓名:");
String name = scanner.next();
System.out.println("请输入学生性别:");
String gender = scanner.next();
System.out.println("请输入学生出生日期:");
String birthday = scanner.next();
System.out.println("请输入学生高考分数:");
double score = scanner.nextDouble();
System.out.println("请输入学生专业:");
String field = scanner.next();
System.out.println("请输入学生班级:");
String className = scanner.next();
Student student = new Student(id, name, gender, birthday, score, field, className);
studentList.add(student);
System.out.println("学生信息已添加!");
}
private static void deleteStudent(ArrayList<Student> studentList, Scanner scanner) {
System.out.println("请输入要删除的学生编号:");
int id = scanner.nextInt();
for (Student student : studentList) {
if (student.getId() == id) {
studentList.remove(student);
System.out.println("学生信息已删除!");
return;
}
}
System.out.println("未找到该学生!");
}
private static void modifyStudent(ArrayList<Student> studentList, Scanner scanner) {
System.out.println("请输入要修改的学生编号:");
int id = scanner.nextInt();
for (Student student : studentList) {
if (student.getId() == id) {
System.out.println("请输入新的学生姓名:");
String name = scanner.next();
System.out.println("请输入新的学生性别:");
String gender = scanner.next();
System.out.println("请输入新的学生出生日期:");
String birthday = scanner.next();
System.out.println("请输入新的学生高考分数:");
double score = scanner.nextDouble();
System.out.println("请输入新的学生专业:");
String field = scanner.next();
System.out.println("请输入新的学生班级:");
String className = scanner.next();
student.setName(name);
student.setGender(gender);
student.setBirthday(birthday);
student.setScore(score);
student.setField(field);
student.setClassName(className);
System.out.println("学生信息已修改!");
return;
}
}
System.out.println("未找到该学生!");
}
private static void queryStudent(ArrayList<Student> studentList, Scanner scanner) {
System.out.println("请输入要查询的学生编号:");
int id = scanner.nextInt();
for (Student student : studentList) {
if (student.getId() == id) {
System.out.println(student.toString());
return;
}
}
System.out.println("未找到该学生!");
}
}
class Person {
private int id;
private String name;
private String gender;
private String birthday;
public Person(int id, String name, String gender, String birthday) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
}
public int getId() {
return id;
}
public void setId(int 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;
}
@Override
public String toString() {
return "编号:" + id + ",姓名:" + name + ",性别:" + gender + ",出生日期:" + birthday;
}
}
class Teacher extends Person {
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) {
super(id, name, gender, birthday);
this.department = department;
this.title = title;
this.salary = salary;
}
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 super.toString() + ",部门:" + department + ",职称:" + title + ",工资:" + salary;
}
}
class Student extends Person {
private double score;
private String field;
private String className;
public Student(int id, String name, String gender, String birthday, double score, String field, String className) {
super(id, name, gender, birthday);
this.score = score;
this.field = field;
this.className = className;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
@Override
public String toString() {
return super.toString() + ",高考分数:" + score + ",专业:" + field + ",班级:" + className;
}
}
```
以上是一个简单的学校人事管理系统的JAVA代码实现,可以实现教师和学生的基本信息添加、删除、修改和查询。
阅读全文