java程序设计:员工管理系统
时间: 2024-01-04 22:04:00 浏览: 67
java_staff_manager_system.zip_java 员工管理 系统_java 毕业设计_员工 毕业_员工管理
5星 · 资源好评率100%
以下是一个简单的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 EmployeeManagementSystem {
private List<Employee> employees;
public EmployeeManagementSystem() {
employees = new ArrayList<>();
}
public void addEmployee(Employee employee) {
employees.add(employee);
}
public void removeEmployee(Employee employee) {
employees.remove(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 Main {
public static void main(String[] args) {
EmployeeManagementSystem system = new EmployeeManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("1. Add Employee");
System.out.println("2. Remove Employee");
System.out.println("3. Display Employees");
System.out.println("4. 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);
system.addEmployee(employee);
System.out.println("Employee added successfully!");
break;
case 2:
System.out.print("Enter employee name to remove: ");
String nameToRemove = scanner.next();
Employee employeeToRemove = null;
for (Employee emp : system.getEmployees()) {
if (emp.getName().equals(nameToRemove)) {
employeeToRemove = emp;
break;
}
}
if (employeeToRemove != null) {
system.removeEmployee(employeeToRemove);
System.out.println("Employee removed successfully!");
} else {
System.out.println("Employee not found!");
}
break;
case 3:
system.displayEmployees();
break;
case 4:
System.exit(0);
break;
default:
System.out.println("Invalid choice!");
}
}
}
}
```
这个程序实现了一个简单的员工管理系统,可以添加、删除和显示员工信息。用户可以通过控制台菜单选择不同的操作。你可以根据自己的需求进行扩展和修改。
阅读全文