你好,请问你能用JAVA实现程序模拟简单的企业职工管理系统。编写程序实现以下要求: (1)请按继承层次构建企业的各种职工类型,包括超类Employee,以及相应的子类Manager、Secretary和Programmer,从Manager继承又可得到Executive。超类Employee有编号,姓名,年龄,薪金、地址和雇佣日期等信息。 (2)用户可以根据职工编号或职工姓名查找所需的信息。管理人员可以增加,删除数据;可以写入一个数据,查找一个数据,或删除一个数据;此外,管理人员可以增加或降低每个职工的薪金。程序通过ArrayList来实现增加,查找,删除数据。
时间: 2024-03-19 12:44:17 浏览: 85
java职工工资管理系统,包括导入java代码步骤录屏、导入数据库步骤录屏。有源代码和实验报告,代码有详细的注释,直接导入就可
5星 · 资源好评率100%
好的,我可以帮你解答这个问题。
下面是一个简单的企业职工管理系统的JAVA代码实现,你可以参考一下。
```
import java.util.ArrayList;
//职工类
class Employee {
private String id; //编号
private String name; //姓名
private int age; //年龄
private double salary; //薪金
private String address; //地址
private String hireDate; //雇佣日期
public Employee(String id, String name, int age, double salary, String address, String hireDate) {
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
this.address = address;
this.hireDate = hireDate;
}
//getter、setter方法
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getHireDate() {
return hireDate;
}
public void setHireDate(String hireDate) {
this.hireDate = hireDate;
}
//重写toString方法
@Override
public String toString() {
return "编号:" + id + ",姓名:" + name + ",年龄:" + age + ",薪金:" + salary + ",地址:" + address + ",雇佣日期:" + hireDate;
}
}
//经理类
class Manager extends Employee {
private String department; //部门
public Manager(String id, String name, int age, double salary, String address, String hireDate, String department) {
super(id, name, age, salary, address, hireDate);
this.department = department;
}
//getter、setter方法
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
//重写toString方法
@Override
public String toString() {
return super.toString() + ",部门:" + department;
}
}
//秘书类
class Secretary extends Employee {
private String boss; //上司
public Secretary(String id, String name, int age, double salary, String address, String hireDate, String boss) {
super(id, name, age, salary, address, hireDate);
this.boss = boss;
}
//getter、setter方法
public String getBoss() {
return boss;
}
public void setBoss(String boss) {
this.boss = boss;
}
//重写toString方法
@Override
public String toString() {
return super.toString() + ",上司:" + boss;
}
}
//程序员类
class Programmer extends Employee {
private String language; //编程语言
public Programmer(String id, String name, int age, double salary, String address, String hireDate, String language) {
super(id, name, age, salary, address, hireDate);
this.language = language;
}
//getter、setter方法
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
//重写toString方法
@Override
public String toString() {
return super.toString() + ",编程语言:" + language;
}
}
//执行官类
class Executive extends Manager {
public Executive(String id, String name, int age, double salary, String address, String hireDate, String department) {
super(id, name, age, salary, address, hireDate, department);
}
//重写toString方法
@Override
public String toString() {
return super.toString();
}
}
//企业职工管理系统类
public class EmployeeManagementSystem {
private ArrayList<Employee> employeeList; //职工列表
public EmployeeManagementSystem() {
employeeList = new ArrayList<>();
}
//增加职工
public void addEmployee(Employee employee) {
employeeList.add(employee);
System.out.println("职工信息已添加!");
}
//删除职工
public void deleteEmployee(String id) {
for (Employee employee : employeeList) {
if (employee.getId().equals(id)) {
employeeList.remove(employee);
System.out.println("职工信息已删除!");
return;
}
}
System.out.println("未找到该职工信息!");
}
//查找职工
public void searchEmployee(String keyword) {
boolean flag = false;
for (Employee employee : employeeList) {
if (employee.getId().equals(keyword) || employee.getName().equals(keyword)) {
System.out.println(employee);
flag = true;
}
}
if (!flag) {
System.out.println("未找到相关职工信息!");
}
}
//增加薪金
public void addSalary(String id, double amount) {
for (Employee employee : employeeList) {
if (employee.getId().equals(id)) {
employee.setSalary(employee.getSalary() + amount);
System.out.println("薪金已增加!");
return;
}
}
System.out.println("未找到该职工信息!");
}
//降低薪金
public void reduceSalary(String id, double amount) {
for (Employee employee : employeeList) {
if (employee.getId().equals(id)) {
employee.setSalary(employee.getSalary() - amount);
System.out.println("薪金已降低!");
return;
}
}
System.out.println("未找到该职工信息!");
}
//测试程序
public static void main(String[] args) {
EmployeeManagementSystem system = new EmployeeManagementSystem();
//增加职工
Employee employee1 = new Manager("001", "张三", 30, 8000, "北京市", "2021-01-01", "销售部");
Employee employee2 = new Secretary("002", "李四", 25, 5000, "上海市", "2021-01-02", "张三");
Employee employee3 = new Programmer("003", "王五", 28, 6000, "广州市", "2021-01-03", "Java");
Employee employee4 = new Executive("004", "赵六", 35, 10000, "深圳市", "2021-01-04", "总裁办公室");
system.addEmployee(employee1);
system.addEmployee(employee2);
system.addEmployee(employee3);
system.addEmployee(employee4);
//删除职工
system.deleteEmployee("002");
//查找职工
system.searchEmployee("王五");
//增加薪金
system.addSalary("001", 1000);
//降低薪金
system.reduceSalary("004", 2000);
}
}
```
这个程序实现了根据职工编号或职工姓名查找职工信息、增加、删除职工信息、增加、降低职工薪金等基本功能。利用继承实现了职工类别的分类,并通过ArrayList来实现对职工信息的存储和操作。
阅读全文