控制台工资管理系统

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

// 员工类
class Employee {
    private String id;
    private String name;
    private String department;
    private double salary;

    public Employee(String id, String name, String department, double salary) {
        this.id = id;
        this.name = name;
        this.department = department;
        this.salary = salary;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getDepartment() {
        return department;
    }

    public double getSalary() {
        return salary;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "👤 员工信息 {" +
                "工号='" + id + '\'' +
                ", 姓名='" + name + '\'' +
                ", 部门='" + department + '\'' +
                ", 工资=¥" + salary +
                '}';
    }
}

// 工资管理系统类
public class SalaryManagementSystem {
    private static List<Employee> employees = new ArrayList<>();
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        login(); // 登录
        boolean exit = false;
        while (!exit) {
            displayMenu();
            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline left-over

            switch (choice) {
                case 1:
                    addEmployee();
                    break;
                case 2:
                    deleteEmployee();
                    break;
                case 3:
                    updateEmployee();
                    break;
                case 4:
                    queryEmployee();
                    break;
                case 5:
                    showStatistics();
                    break;
                case 6:
                    exit = true;
                    break;
                case 7:
                    sortEmployeesBySalary();
                    break;
                // 显示所有员工信息
                case 8:
                    displayAllEmployees();
                    break;
                default:
                    System.out.println("❌ 请输入有效的选项!");
                    break;
            }
        }
        System.out.println("👋 感谢使用工资管理系统!");
    }
    private static void sortEmployeesBySalary() {
        if (employees.isEmpty()) {
            System.out.println("⚠️ 当前没有员工信息!");
            return;
        }

        employees.sort(Comparator.comparingDouble(Employee::getSalary));

        System.out.println("✨ 员工信息按工资升序排序:");
        for (Employee emp : employees) {
            System.out.println(emp);
        }
    }
    // 显示所有员工信息
    private static void displayAllEmployees() {
        if (employees.isEmpty()) {
            System.out.println("⚠️ 当前没有员工信息!");
            return;
        }

        System.out.println("✨ 所有员工信息:");
        for (Employee emp : employees) {
            System.out.println(emp);
        }
    }
    // 登录功能,这里简单模拟,可以根据实际情况扩展
    private static void login() {
        System.out.println("=== 欢迎使用工资管理系统 ===");
        while (true) {
            System.out.print("🔑 请输入用户名:");
            String username = scanner.nextLine();
            System.out.print("🔑 请输入密码:");
            String password = scanner.nextLine();

            // 简单模拟用户名和密码
            if (username.equals("admin") && password.equals("admin")) {
                System.out.println("✅ 登录成功!");
                break;
            } else {
                System.out.println("❌ 用户名或密码错误,请重试!");
            }
        }
    }

    // 显示菜单
    private static void displayMenu() {
        System.out.println("\n请选择操作:");
        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("7. 🔄 按工资排序员工信息");
        System.out.println("8. 📜 显示所有员工信息");
        System.out.print("请输入数字选择操作:");
    }

    // 添加员工信息
    private static void addEmployee() {
        System.out.print("请输入员工工号:");
        String id = scanner.nextLine();
        System.out.print("请输入员工姓名:");
        String name = scanner.nextLine();
        System.out.print("请输入员工部门:");
        String department = scanner.nextLine();
        System.out.print("请输入员工工资:");
        double salary = scanner.nextDouble();
        scanner.nextLine(); // Consume newline left-over

        Employee newEmployee = new Employee(id, name, department, salary);
        employees.add(newEmployee);
        System.out.println("✅ 员工信息添加成功!");
    }

    // 删除员工信息
    private static void deleteEmployee() {
        System.out.print("请输入要删除的员工工号:");
        String id = scanner.nextLine();

        boolean found = false;
        for (Employee emp : employees) {
            if (emp.getId().equals(id)) {
                employees.remove(emp);
                System.out.println("✅ 员工信息删除成功!");
                found = true;
                break;
            }
        }

        if (!found) {
            System.out.println("❌ 未找到该员工!");
        }
    }

    // 修改员工信息
    private static void updateEmployee() {
        System.out.print("请输入要修改的员工工号:");
        String id = scanner.nextLine();

        boolean found = false;
        for (Employee emp : employees) {
            if (emp.getId().equals(id)) {
                System.out.print("请输入新的员工姓名:");
                String newName = scanner.nextLine();
                System.out.print("请输入新的员工部门:");
                String newDept = scanner.nextLine();
                System.out.print("请输入新的员工工资:");
                double newSalary = scanner.nextDouble();
                scanner.nextLine(); // Consume newline left-over

                emp.setName(newName);
                emp.setDepartment(newDept);
                emp.setSalary(newSalary);
                System.out.println("✅ 员工信息修改成功!");
                found = true;
                break;
            }
        }

        if (!found) {
            System.out.println("❌ 未找到该员工!");
        }
    }

    // 查询员工信息
    private static void queryEmployee() {
        System.out.print("请输入要查询的员工工号:");
        String id = scanner.nextLine();

        boolean found = false;
        for (Employee emp : employees) {
            if (emp.getId().equals(id)) {
                System.out.println(emp);
                found = true;
                break;
            }
        }

        if (!found) {
            System.out.println("❌ 未找到该员工!");
        }
    }

    // 查看统计信息
    private static void showStatistics() {
        if (employees.isEmpty()) {
            System.out.println("⚠️ 当前没有员工信息!");
            return;
        }

        double totalSalary = 0;
        double maxSalary = Double.MIN_VALUE;
        double minSalary = Double.MAX_VALUE;

        for (Employee emp : employees) {
            double salary = emp.getSalary();
            totalSalary += salary;
            if (salary > maxSalary) {
                maxSalary = salary;
            }
            if (salary < minSalary) {
                minSalary = salary;
            }
        }

        double averageSalary = totalSalary / employees.size();
        System.out.println("📊 统计信息:");
        System.out.println("总员工人数:" + employees.size());
        System.out.println("平均工资:¥" + averageSalary);
        System.out.println("最高工资:¥" + maxSalary);
        System.out.println("最低工资:¥" + minSalary);
    }
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C#中,创建一个职工工资管理系统通常会涉及到一些基本的数据结构,如数组、列表、字典等,用于存储和管理职工信息和工资数据。以下是一个简化的系统概述: 1. **员工类(Employee)**: 定义一个包含员工ID、姓名、职位和工资等属性的类,可能还会包括一些方法,如计算年工资、领取奖金等。 ```csharp public class Employee { public int Id { get; set; } public string Name { get; set; } public string Position { get; set; } public decimal Salary { get; set; } // 方法 public decimal AnnualSalary() => Salary * 12; public void ReceiveBonus(decimal bonus) => Salary += bonus; } ``` 2. **工资单类(SalarySheet)**: 可能包含一个列表或集合来存储所有员工的工资信息,并提供添加员工、查询工资等操作。 ```csharp public class SalarySheet { private List<Employee> employees; public SalarySheet() { employees = new List<Employee>(); } public void AddEmployee(Employee emp) { employees.Add(emp); } public decimal GetTotalSalary() { return employees.Sum(e => e.Salary); } } ``` 3. **主程序和用户界面**: 用户可以通过控制台应用或图形用户界面(GUI)与工资管理系统交互,例如输入新员工信息、查看工资总额等。 ```csharp class Program { static void Main(string[] args) { SalarySheet system = new SalarySheet(); system.AddEmployee(new Employee { Id = 1, Name = "张三", Position = "经理", Salary = 10000 }); // 更多操作... } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值