用java实现人事管理系统
时间: 2023-10-02 15:03:31 浏览: 40
实现人事管理系统可以使用 Java 编程语言。以下是一个简单的人事管理系统的示例代码:
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Employee {
private String name;
private int age;
private String position;
public Employee(String name, int age, String position) {
this.name = name;
this.age = age;
this.position = position;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getPosition() {
return position;
}
}
class HRSystem {
private List<Employee> employees;
public HRSystem() {
employees = new ArrayList<>();
}
public void addEmployee(Employee employee) {
employees.add(employee);
}
public void displayEmployees() {
for (Employee employee : employees) {
System.out.println("Name: " + employee.getName());
System.out.println("Age: " + employee.getAge());
System.out.println("Position: " + employee.getPosition());
System.out.println("--------------------");
}
}
}
public class HRManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HRSystem hrSystem = new HRSystem();
while (true) {
System.out.println("1. Add Employee");
System.out.println("2. Display Employees");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter employee name: ");
String name = scanner.next();
System.out.print("Enter employee age: ");
int age = scanner.nextInt();
System.out.print("Enter employee position: ");
String position = scanner.next();
Employee employee = new Employee(name, age, position);
hrSystem.addEmployee(employee);
System.out.println("Employee added successfully!");
break;
case 2:
hrSystem.displayEmployees();
break;
case 3:
System.exit(0);
default:
System.out.println("Invalid choice!");
}
}
}
}
```
这个示例代码实现了一个简单的人事管理系统,可以添加员工信息、显示员工列表和退出程序。你可以根据自己的需求进行修改和扩展。