写一个java的人力资源管理系统
时间: 2023-08-16 10:09:44 浏览: 110
好的,下面是一个简单的Java人力资源管理系统的示例代码:
```
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class HRManagementSystem {
private List<Employee> employees;
public HRManagementSystem() {
employees = new ArrayList<>();
}
public void addEmployee(Employee employee) {
employees.add(employee);
}
public void removeEmployee(Employee employee) {
employees.remove(employee);
}
public List<Employee> getAllEmployees() {
return employees;
}
public List<Employee> searchEmployees(String keyword) {
List<Employee> result = new ArrayList<>();
for (Employee employee : employees) {
if (employee.getFirstName().contains(keyword) || employee.getLastName().contains(keyword)) {
result.add(employee);
}
}
return result;
}
public static void main(String[] args) {
HRManagementSystem system = new HRManagementSystem();
// 添加员工
Employee employee1 = new Employee("Tom", "Smith", new Date(), 3000);
Employee employee2 = new Employee("Alice", "Jones", new Date(), 3500);
Employee employee3 = new Employee("Bob", "Brown", new Date(), 4000);
system.addEmployee(employee1);
system.addEmployee(employee2);
system.addEmployee(employee3);
// 搜索员工
List<Employee> searchResult = system.searchEmployees("Tom");
System.out.println("搜索结果:");
for (Employee employee : searchResult) {
System.out.println(employee.getFirstName() + " " + employee.getLastName());
}
// 删除员工
system.removeEmployee(employee3);
System.out.println("删除员工后,现有员工:");
for (Employee employee : system.getAllEmployees()) {
System.out.println(employee.getFirstName() + " " + employee.getLastName());
}
}
}
class Employee {
private String firstName;
private String lastName;
private Date hireDate;
private int salary;
public Employee(String firstName, String lastName, Date hireDate, int salary) {
this.firstName = firstName;
this.lastName = lastName;
this.hireDate = hireDate;
this.salary = salary;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public Date getHireDate() {
return hireDate;
}
public int getSalary() {
return salary;
}
}
```
以上示例代码实现了人力资源管理系统的一个简单功能,包括员工信息管理、搜索员工和删除员工。在实际项目中,还需要添加更多的模块和功能,比如薪资管理、培训管理、招聘管理等。
阅读全文