采用面向对象的思想,采用集合存储三个部门职 位不同的 14 位员工,员工信息(工号,姓名,职位,入职时间、上司 工号、工资、补贴、部门),统计每个部分的总工资,每 个部分的职位,以及对员工工资进行降序...

这篇博客介绍了如何使用面向对象思想设计程序,通过创建`Department`和`Employee`类来管理组织结构。每个部门包含一组员工,可以计算总薪资和获取职位分布。员工类包含了基本属性如ID、姓名、职位等。这种设计允许方便地对员工进行操作和统计。
摘要由CSDN通过智能技术生成

面向对象思想是一种程序设计思想,它将程序看作一系列对象的集合,每个对象都有自己的属性和行为。

为了解决上述问题,我们需要定义三个部门,每个部门都有若干个员工。我们可以使用一个类来表示部门,另一个类来表示员工。

我们可以使用一个集合来存储所有员工,这样就可以对员工进行排序和统计。

例如,我们可以定义以下类:

class Department {
  String name;
  Set<Employee> employees;

  Department(this.name, this.employees);

  double getTotalSalary() {
    double total = 0;
    for (Employee employee in employees) {
      total += employee.salary + employee.allowance;
    }
    return total;
  }

  Set<String> getPositions() {
    Set<String> positions = Set();
    for (Employee employee in employees) {
      positions.add(employee.position);
    }
    return positions;
  }
}

class Employee {
  int id;
  String name;
  String position;
  DateTime hireDate;
  int managerId;
  double salary;
  double allowance;
  Department department;

  Employee(this.id, this.name, this.position, this.hireDate, this.managerId, this.salary, this.allowance, this.department);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值