Java 员工管理系统

本系统使用 Java 语言编写,实现了员工管理的增、删、改、查功能,并运用循环登录、循环选择,使用数组存储员工信息。系统包含 Staff 类和 StaffManager 类,定义了相应的登录、查看信息、修改信息、新增员工、查找员工、更新员工信息、删除员工等方法。

Staff 类java public class Staff { private String empNo; // 工号 private String password; // 密码 private String empName; // 姓名 private String gender; // 性别 private String idCardNo; // 身份证号 private int age; // 年龄 private int seniority; // 工龄 private double wages; // 工资 private String title; // 职称 private String department; // 所属部门 private String phoneNum; // 联系方式 private String homeAddress; // 家庭住址

public Staff(String empNo, String password, String empName, String gender, String idCardNo, int age, int seniority, double wages, String title, String department, String phoneNum, String homeAddress) {
    this.empNo = empNo;
    this.password = password;
    this.empName = empName;
    this.gender = gender;
    this.idCardNo = idCardNo;
    this.age = age;
    this.seniority = seniority;
    this.wages = wages;
    this.title = title;
    this.department = department;
    this.phoneNum = phoneNum;
    this.homeAddress = homeAddress;
}

// Getter 和 Setter 方法

// 登录系统方法
public boolean login(String username, String password) {
    if (this.empNo.equals(username) && this.password.equals(password)) {
        return true;
    } else {
        return false;
    }
}

// 查看个人信息方法
public void showDetail() {
    System.out.println('工号:' + empNo);
    System.out.println('姓名:' + empName);
    System.out.println('性别:' + gender);
    System.out.println('身份证号:' + idCardNo);
    System.out.println('年龄:' + age);
    System.out.println('工龄:' + seniority);
    System.out.println('工资:' + wages);
    System.out.println('职称:' + title);
    System.out.println('所属部门:' + department);
    System.out.println('联系方式:' + phoneNum);
    System.out.println('家庭住址:' + homeAddress);
}

// 修改个人信息方法
public void alterDetail(String username, String password, String phoneNum, String homeAddress) {
    if (login(username, password)) {
        this.phoneNum = phoneNum;
        this.homeAddress = homeAddress;
        System.out.println('修改成功!');
    } else {
        System.out.println('登录失败,无法修改个人信息!');
    }
}

}


**StaffManager 类**java
import java.util.Arrays;
import java.util.Scanner;

public class StaffManager {
    private Staff[] staffLists; // 员工列表
    private String user; // 管理员账号
    private String password; // 管理员密码

    public StaffManager(Staff[] staffLists, String user, String password) {
        this.staffLists = staffLists;
        this.user = user;
        this.password = password;
    }

    // Getter 和 Setter 方法

    // 添加员工方法
    public void addStaff(Staff newStaff) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入管理员账号:');
        String user = input.next();
        System.out.print('请输入管理员密码:');
        String password = input.next();
        if (this.user.equals(user) && this.password.equals(password)) {
            int length = staffLists.length;
            staffLists = Arrays.copyOf(staffLists, length + 1);
            staffLists[length] = newStaff;
            System.out.println('添加成功!');
        } else {
            System.out.println('管理员账号或密码错误,无法添加员工!');
        }
    }

    // 查找指定员工方法
    public Staff findStaff(String empNo) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入管理员账号:');
        String user = input.next();
        System.out.print('请输入管理员密码:');
        String password = input.next();
        if (this.user.equals(user) && this.password.equals(password)) {
            for (Staff staff : staffLists) {
                if (staff.getEmpNo().equals(empNo)) {
                    return staff;
                }
            }
            System.out.println('没有找到对应员工!');
            return null;
        } else {
            System.out.println('管理员账号或密码错误,无法查找员工!');
            return null;
        }
    }

    // 更新指定员工信息方法
    public void updateStaffInfo(String empNo, Staff newStaff) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入管理员账号:');
        String user = input.next();
        System.out.print('请输入管理员密码:');
        String password = input.next();
        if (this.user.equals(user) && this.password.equals(password)) {
            for (int i = 0; i < staffLists.length; i++) {
                if (staffLists[i].getEmpNo().equals(empNo)) {
                    staffLists[i] = newStaff;
                    System.out.println('更新成功!');
                    return;
                }
            }
            System.out.println('没有找到对应员工,更新失败!');
        } else {
            System.out.println('管理员账号或密码错误,无法更新员工信息!');
        }
    }

    // 删除指定员工方法
    public void deleteStaff(String empNo) {
        Scanner input = new Scanner(System.in);
        System.out.print('请输入管理员账号:');
        String user = input.next();
        System.out.print('请输入管理员密码:');
        String password = input.next();
        if (this.user.equals(user) && this.password.equals(password)) {
            for (int i = 0; i < staffLists.length; i++) {
                if (staffLists[i].getEmpNo().equals(empNo)) {
                    staffLists = ArrayUtils.remove(staffLists, i);
                    System.out.println('删除成功!');
                    return;
                }
            }
            System.out.println('没有找到对应员工,删除失败!');
        } else {
            System.out.println('管理员账号或密码错误,无法删除员工!');
        }
    }
}

主方法

Java 员工管理系统:增删改查功能实现

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

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