用JAVA1.实现程序模拟简单的企业职工管理系统。编写程序实现以下要求: (1)请按继承层次构建企业的各种职工类型,包括超类Employee,以及相应的子类Manager、Secretary和Programmer,从Manager继承又可得到Executive。超类Employee有编号,姓名,年龄,薪金、地址和雇佣日期等信息。 (2)用户可以根据职工编号或职工姓名查找所需的信息。管理人员可以增加,删除数据;可以写入一个数据,查找一个数据,或删除一个数据;此外,管理人员可以增加或降低每个职工的薪金。程序通过ArrayList来实现增加,查找,删除数据。
时间: 2024-03-01 22:52:00 浏览: 63
java职工工资管理系统,包括导入java代码步骤录屏、导入数据库步骤录屏。有源代码和实验报告,代码有详细的注释,直接导入就可
5星 · 资源好评率100%
好的,这是一个比较复杂的任务,需要涉及到面向对象的编程思想,也需要一些基础的Java语法知识。我会尽力帮你解答,但是可能需要比较长的篇幅。首先,我们需要定义一个超类Employee,包括编号,姓名,年龄,薪金、地址和雇佣日期等信息:
```java
public class Employee {
private int id; // 编号
private String name; // 姓名
private int age; // 年龄
private double salary; // 薪水
private String address; // 地址
private Date hireDate; // 雇佣日期
// 构造方法
public Employee(int id, String name, int age, double salary, String address, Date hireDate) {
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
this.address = address;
this.hireDate = hireDate;
}
// getter和setter方法
public int getId() {
return id;
}
public void setId(int 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 Date getHireDate() {
return hireDate;
}
public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
}
}
```
接下来,我们需要定义Manager、Secretary和Programmer子类,并从Manager继承得到Executive子类:
```java
public class Manager extends Employee {
private String department; // 部门
public Manager(int id, String name, int age, double salary, String address, Date hireDate, String department) {
super(id, name, age, salary, address, hireDate);
this.department = department;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}
public class Secretary extends Employee {
private String boss; // 上司
public Secretary(int id, String name, int age, double salary, String address, Date hireDate, String boss) {
super(id, name, age, salary, address, hireDate);
this.boss = boss;
}
public String getBoss() {
return boss;
}
public void setBoss(String boss) {
this.boss = boss;
}
}
public class Programmer extends Employee {
private String language; // 编程语言
public Programmer(int id, String name, int age, double salary, String address, Date hireDate, String language) {
super(id, name, age, salary, address, hireDate);
this.language = language;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
}
public class Executive extends Manager {
public Executive(int id, String name, int age, double salary, String address, Date hireDate, String department) {
super(id, name, age, salary, address, hireDate, department);
}
}
```
接下来,我们需要实现一个职工管理系统类,包括增加、查找、删除和修改职工信息的方法:
```java
import java.util.ArrayList;
import java.util.Date;
public class EmployeeManagementSystem {
private ArrayList<Employee> employeeList = new ArrayList<>(); // 职工列表
// 增加职工信息
public void addEmployee(Employee employee) {
employeeList.add(employee);
}
// 根据编号查找职工信息
public Employee findEmployeeById(int id) {
for (Employee employee : employeeList) {
if (employee.getId() == id) {
return employee;
}
}
return null;
}
// 根据姓名查找职工信息
public ArrayList<Employee> findEmployeeByName(String name) {
ArrayList<Employee> result = new ArrayList<>();
for (Employee employee : employeeList) {
if (employee.getName().equals(name)) {
result.add(employee);
}
}
return result;
}
// 删除职工信息
public void deleteEmployee(Employee employee) {
employeeList.remove(employee);
}
// 修改职工薪水
public void updateSalary(Employee employee, double salary) {
employee.setSalary(salary);
}
// 获取职工列表
public ArrayList<Employee> getEmployeeList() {
return employeeList;
}
public static void main(String[] args) {
// 创建一个职工管理系统实例
EmployeeManagementSystem ems = new EmployeeManagementSystem();
// 增加职工信息
ems.addEmployee(new Manager(1, "Tom", 30, 10000, "北京", new Date(), "销售部"));
ems.addEmployee(new Secretary(2, "Mary", 25, 5000, "北京", new Date(), "Tom"));
ems.addEmployee(new Programmer(3, "Jack", 28, 8000, "上海", new Date(), "Java"));
ems.addEmployee(new Executive(4, "Jerry", 35, 15000, "北京", new Date(), "财务部"));
// 查找职工信息
Employee employee1 = ems.findEmployeeById(1);
System.out.println(employee1.getName() + ", " + employee1.getSalary());
ArrayList<Employee> employee2 = ems.findEmployeeByName("Mary");
for (Employee employee : employee2) {
System.out.println(employee.getName() + ", " + employee.getSalary());
}
// 修改职工薪水
ems.updateSalary(employee1, 12000);
System.out.println(employee1.getName() + ", " + employee1.getSalary());
// 删除职工信息
ems.deleteEmployee(employee2.get(0));
System.out.println(ems.getEmployeeList().size());
}
}
```
以上是一个简单的职工管理系统的Java实现,包括超类Employee和子类Manager、Secretary和Programmer、Executive的定义,以及职工管理系统类EmployeeManagementSystem的实现。该系统可以通过增加、查找、删除和修改职工信息的方法来管理职工信息。
阅读全文