Java 教职工管理系统

这是一个使用 Java 编写的教职工管理系统,它可以实现以下功能:

  1. 添加教职工信息 (包括姓名、性别、出生日期、身份证号码、联系电话、家庭住址、职位、工作年限等基本信息,以及工资水平、岗位津贴、绩效奖金等工资信息,以及出勤情况、请假情况、加班情况等考勤信息)。
  2. 删除教职工信息
  3. 修改教职工信息
  4. 查询教职工信息 (按照姓名、身份证号码、职位、工作年限等进行查询)。
  5. 统计教职工工资情况 (按照职位、工作年限、绩效奖金等进行统计)。
  6. 统计教职工考勤情况 (按照出勤情况、请假情况、加班情况等进行统计)。
  7. 输出所有教职工信息

代码示例

import java.util.ArrayList;
import java.util.Scanner;

public class EmployeeManagementSystem {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ArrayList<Employee> employeeList = new ArrayList<>();

        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. 退出系统');

            System.out.print('请选择操作:');
            int choice = input.nextInt();

            switch (choice) {
                case 1:
                    addEmployee(employeeList);
                    break;
                case 2:
                    deleteEmployee(employeeList);
                    break;
                case 3:
                    modifyEmployee(employeeList);
                    break;
                case 4:
                    queryEmployee(employeeList);
                    break;
                case 5:
                    statisticsSalary(employeeList);
                    break;
                case 6:
                    statisticsAttendance(employeeList);
                    break;
                case 7:
                    outputEmployee(employeeList);
                    break;
                case 0:
                    System.out.println('谢谢使用教职工管理系统!');
                    System.exit(0);
                default:
                    System.out.println('输入有误,请重新选择操作!');
            }
        }
    }

    public static void addEmployee(ArrayList<Employee> employeeList) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入姓名:');
        String name = input.next();
        System.out.print('请输入性别:');
        String gender = input.next();
        System.out.print('请输入出生日期:');
        String birthdate = input.next();
        System.out.print('请输入身份证号码:');
        String idNumber = input.next();
        System.out.print('请输入联系电话:');
        String phoneNumber = input.next();
        System.out.print('请输入家庭住址:');
        String address = input.next();
        System.out.print('请输入职位:');
        String position = input.next();
        System.out.print('请输入工作年限:');
        int workYears = input.nextInt();
        System.out.print('请输入工资水平:');
        double salary = input.nextDouble();
        System.out.print('请输入岗位津贴:');
        double jobAllowance = input.nextDouble();
        System.out.print('请输入绩效奖金:');
        double performanceBonus = input.nextDouble();
        System.out.print('请输入出勤情况:');
        String attendance = input.next();
        System.out.print('请输入请假情况:');
        String leave = input.next();
        System.out.print('请输入加班情况:');
        String overtime = input.next();

        Employee employee = new Employee(name, gender, birthdate, idNumber, phoneNumber, address, position, workYears, salary, jobAllowance, performanceBonus, attendance, leave, overtime);
        employeeList.add(employee);
        System.out.println('教职工信息添加成功!');
    }

    public static void deleteEmployee(ArrayList<Employee> employeeList) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入要删除的教职工姓名:');
        String name = input.next();

        for (Employee employee : employeeList) {
            if (employee.getName().equals(name)) {
                employeeList.remove(employee);
                System.out.println('教职工信息删除成功!');
                return;
            }
        }

        System.out.println('未找到对应的教职工信息!');
    }

    public static void modifyEmployee(ArrayList<Employee> employeeList) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入要修改的教职工姓名:');
        String name = input.next();

        for (Employee employee : employeeList) {
            if (employee.getName().equals(name)) {
                System.out.print('请输入新的姓名:');
                String newName = input.next();
                employee.setName(newName);
                System.out.print('请输入新的性别:');
                String newGender = input.next();
                employee.setGender(newGender);
                System.out.print('请输入新的出生日期:');
                String newBirthdate = input.next();
                employee.setBirthdate(newBirthdate);
                System.out.print('请输入新的身份证号码:');
                String newIdNumber = input.next();
                employee.setIdNumber(newIdNumber);
                System.out.print('请输入新的联系电话:');
                String newPhoneNumber = input.next();
                employee.setPhoneNumber(newPhoneNumber);
                System.out.print('请输入新的家庭住址:');
                String newAddress = input.next();
                employee.setAddress(newAddress);
                System.out.print('请输入新的职位:');
                String newPosition = input.next();
                employee.setPosition(newPosition);
                System.out.print('请输入新的工作年限:');
                int newWorkYears = input.nextInt();
                employee.setWorkYears(newWorkYears);
                System.out.print('请输入新的工资水平:');
                double newSalary = input.nextDouble();
                employee.setSalary(newSalary);
                System.out.print('请输入新的岗位津贴:');
                double newJobAllowance = input.nextDouble();
                employee.setJobAllowance(newJobAllowance);
                System.out.print('请输入新的绩效奖金:');
                double newPerformanceBonus = input.nextDouble();
                employee.setPerformanceBonus(newPerformanceBonus);
                System.out.print('请输入新的出勤情况:');
                String newAttendance = input.next();
                employee.setAttendance(newAttendance);
                System.out.print('请输入新的请假情况:');
                String newLeave = input.next();
                employee.setLeave(newLeave);
                System.out.print('请输入新的加班情况:');
                String newOvertime = input.next();
                employee.setOvertime(newOvertime);

                System.out.println('教职工信息修改成功!');
                return;
            }
        }

        System.out.println('未找到对应的教职工信息!');
    }

    public static void queryEmployee(ArrayList<Employee> employeeList) {
        Scanner input = new Scanner(System.in);
        System.out.println('请选择查询方式:');
        System.out.println('1. 姓名');
        System.out.println('2. 身份证号码');
        System.out.println('3. 职位');
        System.out.println('4. 工作年限');
        int choice = input.nextInt();

        switch (choice) {
            case 1:
                System.out.print('请输入教职工姓名:');
                String name = input.next();
                for (Employee employee : employeeList) {
                    if (employee.getName().equals(name)) {
                        employee.output();
                        return;
                    }
                }
                System.out.println('未找到对应的教职工信息!');
                break;
            case 2:
                System.out.print('请输入教职工身份证号码:');
                String idNumber = input.next();
                for (Employee employee : employeeList) {
                    if (employee.getIdNumber().equals(idNumber)) {
                        employee.output();
                        return;
                    }
                }
                System.out.println('未找到对应的教职工信息!');
                break;
            case 3:
                System.out.print('请输入教职工职位:');
                String position = input.next();
                for (Employee employee : employeeList) {
                    if (employee.getPosition().equals(position)) {
                        employee.output();
                        return;
                    }
                }
                System.out.println('未找到对应的教职工信息!');
                break;
            case 4:
                System.out.print('请输入教职工工作年限:');
                int workYears = input.nextInt();
                for (Employee employee : employeeList) {
                    if (employee.getWorkYears() == workYears) {
                        employee.output();
                        return;
                    }
                }
                System.out.println('未找到对应的教职工信息!');
                break;
            default:
                System.out.println('输入有误,请重新选择查询方式!');
        }
    }

    public static void statisticsSalary(ArrayList<Employee> employeeList) {
        Scanner input = new Scanner(System.in);
        System.out.println('请选择统计方式:');
        System.out.println('1. 职位');
        System.out.println('2. 工作年限');
        System.out.println('3. 绩效奖金');
        int choice = input.nextInt();

        switch (choice) {
            case 1:
                System.out.print('请输入职位:');
                String position = input.next();
                double totalSalary = 0;
                for (Employee employee : employeeList) {
                    if (employee.getPosition().equals(position)) {
                        totalSalary += employee.calculateSalary();
                    }
                }
                System.out.println(position + '的总工资为:' + totalSalary);
                break;
            case 2:
                System.out.print('请输入工作年限:');
                int workYears = input.nextInt();
                double totalSalary2 = 0;
                for (Employee employee : employeeList) {
                    if (employee.getWorkYears() == workYears) {
                        totalSalary2 += employee.calculateSalary();
                    }
                }
                System.out.println('工作' + workYears + '年的教职工的总工资为:' + totalSalary2);
                break;
            case 3:
                double totalSalary3 = 0;
                for (Employee employee : employeeList) {
                    totalSalary3 += employee.calculateSalary();
                }
                System.out.println('所有教职工的总工资为:' + totalSalary3);
                break;
            default:
                System.out.println('输入有误,请重新选择统计方式!');
        }
    }

    public static void statisticsAttendance(ArrayList<Employee> employeeList) {
        Scanner input = new Scanner(System.in);
        System.out.println('请选择统计方式:');
        System.out.println('1. 出勤情况');
        System.out.println('2. 请假情况');
        System.out.println('3. 加班情况');
        int choice = input.nextInt();

        switch (choice) {
            case 1:
                System.out.print('请输入出勤情况:');
                String attendance = input.next();
                int count = 0;
                for (Employee employee : employeeList) {
                    if (employee.getAttendance().equals(attendance)) {
                        count++;
                    }
                }
                System.out.println('出勤情况为' + attendance + '的教职工有' + count + '人');
                break;
            case 2:
                System.out.print('请输入请假情况:');
                String leave = input.next();
                int count2 = 0;
                for (Employee employee : employeeList) {
                    if (employee.getLeave().equals(leave)) {
                        count2++;
                    }
                }
                System.out.println('请假情况为' + leave + '的教职工有' + count2 + '人');
                break;
            case 3:
                System.out.print('请输入加班情况:');
                String overtime = input.next();
                int count3 = 0;
                for (Employee employee : employeeList) {
                    if (employee.getOvertime().equals(overtime)) {
                        count3++;
                    }
                }
                System.out.println('加班情况为' + overtime + '的教职工有' + count3 + '人');
                break;
            default:
                System.out.println('输入有误,请重新选择统计方式!');
        }
    }

    public static void outputEmployee(ArrayList<Employee> employeeList) {
        System.out.println('教职工信息如下:');
        for (Employee employee : employeeList) {
            employee.output();
        }
    }
}

class Employee {
    private String name;
    private String gender;
    private String birthdate;
    private String idNumber;
    private String phoneNumber;
    private String address;
    private String position;
    private int workYears;
    private double salary;
    private double jobAllowance;
    private double performanceBonus;
    private String attendance;
    private String leave;
    private String overtime;

    public Employee(String name, String gender, String birthdate, String idNumber, String phoneNumber, String address, String position, int workYears, double salary, double jobAllowance, double performanceBonus, String attendance, String leave, String overtime) {
        this.name = name;
        this.gender = gender;
        this.birthdate = birthdate;
        this.idNumber = idNumber;
        this.phoneNumber = phoneNumber;
        this.address = address;
        this.position = position;
        this.workYears = workYears;
        this.salary = salary;
        this.jobAllowance = jobAllowance;
        this.performanceBonus = performanceBonus;
        this.attendance = attendance;
        this.leave = leave;
        this.overtime = overtime;
    }

    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 getBirthdate() {
        return birthdate;
    }

    public void setBirthdate(String birthdate) {
        this.birthdate = birthdate;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public int getWorkYears() {
        return workYears;
    }

    public void setWorkYears(int workYears) {
        this.workYears = workYears;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public double getJobAllowance() {
        return jobAllowance;
    }

    public void setJobAllowance(double jobAllowance) {
        this.jobAllowance = jobAllowance;
    }

    public double getPerformanceBonus() {
        return performanceBonus;
    }

    public void setPerformanceBonus(double performanceBonus) {
        this.performanceBonus = performanceBonus;
    }

    public String getAttendance() {
        return attendance;
    }

    public void setAttendance(String attendance) {
        this.attendance = attendance;
    }

    public String getLeave() {
        return leave;
    }

    public void setLeave(String leave) {
        this.leave = leave;
    }

    public String getOvertime() {
        return overtime;
    }

    public void setOvertime(String overtime) {
        this.overtime = overtime;
    }

    public double calculateSalary() {
        return salary + jobAllowance + performanceBonus;
    }

    public void output() {
        System.out.println('姓名:' + name);
        System.out.println('性别:' + gender);
        System.out.println('出生日期:' + birthdate);
        System.out.println('身份证号码:' + idNumber);
        System.out.println('联系电话:' + phoneNumber);
        System.out.println('家庭住址:' + address);
        System.out.println('职位:' + position);
        System.out.println('工作年限:' + workYears);
        System.out.println('工资水平:' + salary);
        System.out.println('岗位津贴:' + jobAllowance);
        System.out.println('绩效奖金:' + performanceBonus);
        System.out.println('出勤情况:' + attendance);
        System.out.println('请假情况:' + leave);
        System.out.println('加班情况:' + overtime);
        System.out.println('总工资:' + calculateSalary());
        System.out.println('-----------------------');
    }
}

功能说明

  1. 添加教职工信息:程序会提示用户输入教职工的姓名、性别、出生日期、身份证号码、联系电话、家庭住址、职位、工作年限、工资水平、岗位津贴、绩效奖金、出勤情况、请假情况和加班情况,并将这些信息存储到一个 Employee 对象中,然后将该对象添加到 employeeList 列表中。
  2. 删除教职工信息:程序会提示用户输入要删除的教职工姓名,然后在 employeeList 列表中查找该教职工,如果找到则将其删除。
  3. 修改教职工信息:程序会提示用户输入要修改的教职工姓名,然后在 employeeList 列表中查找该教职工,如果找到则允许用户修改该教职工的各种信息。
  4. 查询教职工信息:程序会提示用户选择查询方式,用户可以选择按照姓名、身份证号码、职位或工作年限进行查询,程序会将符合条件的教职工信息显示出来。
  5. 统计教职工工资情况:程序会提示用户选择统计方式,用户可以选择按照职位、工作年限或绩效奖金进行统计,程序会将符合条件的教职工的总工资显示出来。
  6. 统计教职工考勤情况:程序会提示用户选择统计方式,用户可以选择按照出勤情况、请假情况或加班情况进行统计,程序会将符合条件的教职工人数显示出来。
  7. 输出所有教职工信息:程序会将 employeeList 列表中所有教职工的信息显示出来。

使用方法

  1. 将代码保存为 EmployeeManagementSystem.java 文件。
  2. 在命令行中使用 javac EmployeeManagementSystem.java 命令编译代码。
  3. 运行编译后的代码 java EmployeeManagementSystem
  4. 根据程序提示进行操作。

注意事项

  • 为了便于演示,代码中使用 Scanner 类获取用户输入,实际应用中可以考虑使用图形界面或其他更专业的输入方式。
  • 代码中只提供了基本的实现,实际应用中可能需要根据具体需求进行扩展和改进。
  • 为了防止数据丢失,可以考虑将数据存储到文件中,并在程序启动时从文件中读取数据。
  • 代码中没有进行输入验证,实际应用中需要对用户输入进行验证,以防止输入错误导致程序崩溃。
  • 代码中没有进行权限管理,实际应用中需要根据用户的角色设置不同的权限。

原文地址: https://www.cveoy.top/t/topic/oSSa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录