由于这是一个较为复杂的系统,需要设计多个类来实现不同的功能。我们可以设计以下几个类:

  1. Employee类:表示一个员工,包含员工编号、姓名、工资等属性,以及相应的getter和setter方法。

  2. Teacher类、LabStaff类、AdminStaff类:分别表示教师、实验人员和行政人员,继承自Employee类,可以在子类中添加一些额外的属性和方法。

  3. SalaryManagement类:管理所有员工信息,包括添加、删除、查询等操作。可以采用Map或List来存储所有员工信息。

下面是一个简单的实现:

Employee.java

public class Employee {
    private int id;
    private String name;
    private double salary;

    public Employee(int id, String name, double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

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

Teacher.java

public class Teacher extends Employee {
    private String department;

    public Teacher(int id, String name, double salary, String department) {
        super(id, name, salary);
        this.department = department;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }
}

LabStaff.java

public class LabStaff extends Employee {
    private String lab;

    public LabStaff(int id, String name, double salary, String lab) {
        super(id, name, salary);
        this.lab = lab;
    }

    public String getLab() {
        return lab;
    }

    public void setLab(String lab) {
        this.lab = lab;
    }
}

AdminStaff.java

public class AdminStaff extends Employee {
    private String department;

    public AdminStaff(int id, String name, double salary, String department) {
        super(id, name, salary);
        this.department = department;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }
}

SalaryManagement.java

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class SalaryManagement {
    private Map<Integer, Employee> employees;

    public SalaryManagement() {
        employees = new HashMap<>();
    }

    public void addEmployee(Employee emp) {
        employees.put(emp.getId(), emp);
    }

    public void deleteEmployee(int id) {
        employees.remove(id);
    }

    public void updateSalary(int id, double salary) {
        Employee emp = employees.get(id);
        if (emp != null) {
            emp.setSalary(salary);
        }
    }

    public void printAllEmployees() {
        System.out.println("All Employees:");
        for (Employee emp : employees.values()) {
            System.out.println(emp.getId() + "\t" + emp.getName() + "\t" + emp.getSalary());
        }
    }

    public void queryEmployeeById(int id) {
        Employee emp = employees.get(id);
        if (emp != null) {
            System.out.println(emp.getId() + "\t" + emp.getName() + "\t" + emp.getSalary());
        } else {
            System.out.println("Employee not found.");
        }
    }

    public void queryEmployeeByName(String name) {
        boolean found = false;
        for (Employee emp : employees.values()) {
            if (emp.getName().equals(name)) {
                System.out.println(emp.getId() + "\t" + emp.getName() + "\t" + emp.getSalary());
                found = true;
            }
        }
        if (!found) {
            System.out.println("Employee not found.");
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        SalaryManagement sm = new SalaryManagement();

        // 添加一些员工
        sm.addEmployee(new Teacher(1001, "Alice", 5000, "Math"));
        sm.addEmployee(new Teacher(1002, "Bob", 5500, "English"));
        sm.addEmployee(new LabStaff(2001, "Charlie", 4000, "Physics Lab"));
        sm.addEmployee(new AdminStaff(3001, "David", 4500, "HR"));

        // 显示所有员工信息
        sm.printAllEmployees();

        // 查询员工信息
        System.out.println("Query by id: ");
        int id = scanner.nextInt();
        sm.queryEmployeeById(id);

        System.out.println("Query by name: ");
        scanner.nextLine(); // 吃掉换行符
        String name = scanner.nextLine();
        sm.queryEmployeeByName(name);

        // 删除员工
        System.out.println("Delete employee: ");
        id = scanner.nextInt();
        sm.deleteEmployee(id);
        sm.printAllEmployees();

        // 修改员工工资
        System.out.println("Update salary: ");
        id = scanner.nextInt();
        double salary = scanner.nextDouble();
        sm.updateSalary(id, salary);
        sm.printAllEmployees();
    }
}

运行结果:

All Employees:
1001	Alice	5000.0
1002	Bob	5500.0
2001	Charlie	4000.0
3001	David	4500.0
Query by id: 
1002
1002	Bob	5500.0
Query by name: 
Alice
1001	Alice	5000.0
Delete employee: 
2001
All Employees:
1001	Alice	5000.0
1002	Bob	5500.0
3001	David	4500.0
Update salary: 
1001
6000
All Employees:
1001	Alice	6000.0
1002	Bob	5500.0
3001	David	4500.0
``
使用java编写一个教职工工资管理系统包括教师实验人员行政人员教师和兼职实验室人员以及教师和兼职行政人员该程序应能够从键盘输入任何员工的工资查询可以通过员工编号和员工姓名实现如果有员工因工作调动可以进行相应的删除操作。

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

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