用java写一个教师管理系统
时间: 2023-11-09 10:05:35 浏览: 275
教师管理系统可以包括如下功能:
1. 添加、修改、删除教师信息;
2. 查询、排序、筛选教师信息;
3. 统计教师总数、男女比例、教学年限等信息;
4. 记录教师的考勤、请假、奖惩等情况;
5. 自动生成教师工资单;
6. 对教师进行评价和考核。
下面是一个简单的教师管理系统的 Java 代码示例:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class TeacherManagementSystem {
private List<Teacher> teachers = new ArrayList<>();
public void addTeacher() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入教师姓名:");
String name = scanner.nextLine();
System.out.println("请输入教师性别:");
String gender = scanner.nextLine();
System.out.println("请输入教师年龄:");
int age = scanner.nextInt();
System.out.println("请输入教师工号:");
int id = scanner.nextInt();
System.out.println("请输入教师教龄:");
int teachingYears = scanner.nextInt();
System.out.println("请输入教师基本工资:");
double baseSalary = scanner.nextDouble();
Teacher teacher = new Teacher(name, gender, age, id, teachingYears, baseSalary);
teachers.add(teacher);
System.out.println("添加成功!");
}
public void deleteTeacher() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要删除的教师工号:");
int id = scanner.nextInt();
for (int i = 0; i < teachers.size(); i++) {
if (teachers.get(i).getId() == id) {
teachers.remove(i);
System.out.println("删除成功!");
return;
}
}
System.out.println("没有找到该教师!");
}
public void updateTeacher() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要修改的教师工号:");
int id = scanner.nextInt();
for (Teacher teacher : teachers) {
if (teacher.getId() == id) {
System.out.println("请输入教师姓名:");
teacher.setName(scanner.nextLine());
System.out.println("请输入教师性别:");
teacher.setGender(scanner.nextLine());
System.out.println("请输入教师年龄:");
teacher.setAge(scanner.nextInt());
System.out.println("请输入教师教龄:");
teacher.setTeachingYears(scanner.nextInt());
System.out.println("请输入教师基本工资:");
teacher.setBaseSalary(scanner.nextDouble());
System.out.println("修改成功!");
return;
}
}
System.out.println("没有找到该教师!");
}
public void searchTeacher() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查询的教师姓名:");
String name = scanner.nextLine();
for (Teacher teacher : teachers) {
if (teacher.getName().equals(name)) {
System.out.println(teacher);
return;
}
}
System.out.println("没有找到该教师!");
}
public void listTeachers() {
for (Teacher teacher : teachers) {
System.out.println(teacher);
}
}
public void calculateSalary() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要计算工资的教师工号:");
int id = scanner.nextInt();
for (Teacher teacher : teachers) {
if (teacher.getId() == id) {
double salary = teacher.calculateSalary();
System.out.println("教师工号:" + id + ",工资:" + salary);
return;
}
}
System.out.println("没有找到该教师!");
}
public void evaluateTeacher() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要评价的教师工号:");
int id = scanner.nextInt();
for (Teacher teacher : teachers) {
if (teacher.getId() == id) {
System.out.println("请输入评价:");
String evaluation = scanner.nextLine();
teacher.setEvaluation(evaluation);
System.out.println("评价成功!");
return;
}
}
System.out.println("没有找到该教师!");
}
public static void main(String[] args) {
TeacherManagementSystem system = new TeacherManagementSystem();
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("0. 退出");
int choice = scanner.nextInt();
switch (choice) {
case 1:
system.addTeacher();
break;
case 2:
system.deleteTeacher();
break;
case 3:
system.updateTeacher();
break;
case 4:
system.searchTeacher();
break;
case 5:
system.listTeachers();
break;
case 6:
system.calculateSalary();
break;
case 7:
system.evaluateTeacher();
break;
case 0:
System.exit(0);
default:
System.out.println("无效的选择!");
}
}
}
}
class Teacher {
private String name;
private String gender;
private int age;
private int id;
private int teachingYears;
private double baseSalary;
private String evaluation;
public Teacher(String name, String gender, int age, int id, int teachingYears, double baseSalary) {
this.name = name;
this.gender = gender;
this.age = age;
this.id = id;
this.teachingYears = teachingYears;
this.baseSalary = baseSalary;
}
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getTeachingYears() {
return teachingYears;
}
public void setTeachingYears(int teachingYears) {
this.teachingYears = teachingYears;
}
public double getBaseSalary() {
return baseSalary;
}
public void setBaseSalary(double baseSalary) {
this.baseSalary = baseSalary;
}
public String getEvaluation() {
return evaluation;
}
public void setEvaluation(String evaluation) {
this.evaluation = evaluation;
}
public double calculateSalary() {
double salary = baseSalary + teachingYears * 1000;
if (evaluation != null && evaluation.contains("优秀")) {
salary += 500;
}
return salary;
}
@Override
public String toString() {
return "教师姓名:" + name
+ ",教师性别:" + gender
+ ",教师年龄:" + age
+ ",教师工号:" + id
+ ",教师教龄:" + teachingYears
+ ",教师基本工资:" + baseSalary
+ ",教师评价:" + evaluation;
}
}
```
这个示例代码是一个比较简单的教师管理系统,具体的功能和实现可以根据实际需求来进行扩展和改进。
阅读全文