Java1、完成一个企业员工管理系统(EmployeeManagementSystem), 员工信息(工号,姓名,性别,职位,月薪)功能点: 1. 员工入职(添加) 2. 调整员工的月薪 3. 查询所有员工 4. 根据员工的工号显示员工信息 5. 删除指定工号的员工 6. 统计一个月发放的总工资
时间: 2024-04-12 17:31:17 浏览: 98
你好!对于你的问题,我可以为你提供一个基本的 Java 代码示例,来实现企业员工管理系统。请注意,以下示例仅供参考,你可以根据自己的需求进行修改和扩展。
```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Employee {
private int id;
private String name;
private String gender;
private String position;
private double salary;
public Employee(int id, String name, String gender, String position, double salary) {
this.id = id;
this.name = name;
this.gender = gender;
this.position = position;
this.salary = salary;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public String getPosition() {
return position;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
class EmployeeManagementSystem {
private List<Employee> employees;
public EmployeeManagementSystem() {
employees = new ArrayList<>();
}
public void addEmployee(Employee employee) {
employees.add(employee);
System.out.println("员工入职成功!");
}
public void adjustSalary(int id, double newSalary) {
for (Employee employee : employees) {
if (employee.getId() == id) {
employee.setSalary(newSalary);
System.out.println("员工月薪调整成功!");
return;
}
}
System.out.println("找不到指定工号的员工!");
}
public void displayAllEmployees() {
if (employees.isEmpty()) {
System.out.println("暂无员工信息!");
} else {
System.out.println("所有员工信息:");
for (Employee employee : employees) {
System.out.println("工号:" + employee.getId());
System.out.println("姓名:" + employee.getName());
System.out.println("性别:" + employee.getGender());
System.out.println("职位:" + employee.getPosition());
System.out.println("月薪:" + employee.getSalary());
System.out.println("--------------------");
}
}
}
public void displayEmployeeById(int id) {
for (Employee employee : employees) {
if (employee.getId() == id) {
System.out.println("工号:" + employee.getId());
System.out.println("姓名:" + employee.getName());
System.out.println("性别:" + employee.getGender());
System.out.println("职位:" + employee.getPosition());
System.out.println("月薪:" + employee.getSalary());
return;
}
}
System.out.println("找不到指定工号的员工!");
}
public void deleteEmployeeById(int id) {
for (Employee employee : employees) {
if (employee.getId() == id) {
employees.remove(employee);
System.out.println("员工删除成功!");
return;
}
}
System.out.println("找不到指定工号的员工!");
}
public double calculateTotalSalary() {
double totalSalary = 0;
for (Employee employee : employees) {
totalSalary += employee.getSalary();
}
return totalSalary;
}
}
public class Main {
public static void main(String[] args) {
EmployeeManagementSystem system = new EmployeeManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 员工入职");
System.out.println("2. 调整员工的月薪");
System.out.println("3. 查询所有员工");
System.out.println("4. 根据员工的工号显示员工信息");
System.out.println("5. 删除指定工号的员工");
System.out.println("6. 统计一个月发放的总工资");
System.out.println("0. 退出程序");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("请输入员工信息:");
System.out.print("工号:");
int id = scanner.nextInt();
scanner.nextLine(); // 消耗换行符
System.out.print("姓名:");
String name = scanner.nextLine();
System.out.print("性别:");
String gender = scanner.nextLine();
System.out.print("职位:");
String position = scanner.nextLine();
System.out.print("月薪:");
double salary = scanner.nextDouble();
Employee employee = new Employee(id, name, gender, position, salary);
system.addEmployee(employee);
break;
case 2:
System.out.print("请输入要调整月薪的员工工号:");
int adjustId = scanner.nextInt();
System.out.print("请输入新的月薪:");
double newSalary = scanner.nextDouble();
system.adjustSalary(adjustId, newSalary);
break;
case 3:
system.displayAllEmployees();
break;
case 4:
System.out.print("请输入要查询的员工工号:");
int displayId = scanner.nextInt();
system.displayEmployeeById(displayId);
break;
case 5:
System.out.print("请输入要删除的员工工号:");
int deleteId = scanner.nextInt();
system.deleteEmployeeById(deleteId);
break;
case 6:
double totalSalary = system.calculateTotalSalary();
System.out.println("一个月发放的总工资:" + totalSalary);
break;
case 0:
System.out.println("程序已退出。");
return;
default:
System.out.println("无效的选择!");
break;
}
}
}
}
```
这是一个简单的员工管理系统,你可以根据自己的需求进行修改和扩展。希望对你有帮助!如果还有其他问题,请随时提问。
阅读全文