java-继承,编程:某公司的雇员分为以下若干类:

(1) Employee :这是所有员工总的父类。
属性:员工的姓名,员工的生日月份
方法: getSalary(int month)根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100元.
(2)SalariedEmployee : Employee 的子类,拿固定工资的员工。
属性∶月薪。
(3)HourlyEmployee : Employee 的子类,按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放。
属性︰每小时的工资、每月工作的小时数。
(4) SalesEmployee : Employee 的子类,销售,工资由月销售额和提成率决定。
属性:月销售额、提成率.
(5)BasePlusSalesEmployee : SalesEmployee 的子类,有固定底薪的销售人员,工资由底薪加上销售提成部分。。
属性:底薪.
要求:
(1)创建SalariedEmployee、HourlyEmployee、SaleEmployee、BasePlusSalesEmployee四个类的对象各一个
(2)并调用父类getSalary(int money)方法计算某个月这四个对象各自的工资
注意:要求把每个类都做成完全封装,不允许非私有化属性。
编程∶在上一题的基础上,创建一个Employee 数组,分别创建若干不同的Employee对象,并打印某个月的工资.

public class Employee {
    private String name;
    private int month;

    public Employee() {
    }

    public Employee(String name, int month) {
        this.name = name;
        this.month = month;
    }

    public String getName() {
        return name;
    }

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

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public double getSalary(int month) {
        if (month == this.month) {
            return 100;
        }
        return 0;
    }

}

class SalariedEmployee extends Employee {
    private double salary;

    public SalariedEmployee() {
    }

    public SalariedEmployee(double salary) {
        this.salary = salary;
    }

    public SalariedEmployee(String name, int month, double salary) {
        super(name, month);
        this.salary = salary;
    }

    public double getSalary() {
        return salary;
    }

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

    @Override
    public double getSalary(int month) {
        return super.getSalary(month) + salary;
    }

}

class HourlyEmployee extends Employee {
    private double hourlySalary;
    private int hours;

    public HourlyEmployee() {
    }

    public HourlyEmployee(double hourlySalary, int hours) {
        this.hourlySalary = hourlySalary;
        this.hours = hours;
    }

    public HourlyEmployee(String name, int month, double hourlySalary, int hours) {
        super(name, month);
        this.hourlySalary = hourlySalary;
        this.hours = hours;
    }

    public double getHourlySalary() {
        return hourlySalary;
    }

    public void setHourlySalary(double hourlySalary) {
        this.hourlySalary = hourlySalary;
    }

    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    @Override
    public double getSalary(int month) {
        if (hours <= 160) {
            return super.getSalary(month) + hourlySalary * hours;
        } else {
            return super.getSalary(month) + (hours - 160) * 1.5 * hourlySalary + 160 * hourlySalary;
        }
    }
}

class SalesEmployee extends Employee {
    private double sales;//月销额
    private double rate;//提出率

    public SalesEmployee() {
    }

    public SalesEmployee(double sales, double rate) {
        this.sales = sales;
        this.rate = rate;
    }

    public SalesEmployee(String name, int month, double sales, double rate) {
        super(name, month);
        this.sales = sales;
        this.rate = rate;
    }

    public double getSales() {
        return sales;
    }

    public void setSales(double sales) {
        this.sales = sales;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    @Override
    public double getSalary(int month) {
        return super.getSalary(month) + sales + rate;
    }
}

class BasePlusSalesEmployee extends SalesEmployee {
    private double baseSalesEmployee;

    public BasePlusSalesEmployee() {
    }

    public BasePlusSalesEmployee(double baseSalesEmployee) {
        this.baseSalesEmployee = baseSalesEmployee;
    }

    public BasePlusSalesEmployee(double sales, double rate, double baseSalesEmployee) {
        super(sales, rate);
        this.baseSalesEmployee = baseSalesEmployee;
    }

    public BasePlusSalesEmployee(String name, int month, double sales, double rate, double baseSalesEmployee) {
        super(name, month, sales, rate);
        this.baseSalesEmployee = baseSalesEmployee;
    }

    public double getBaseSalesEmployee() {
        return baseSalesEmployee;
    }

    public void setBaseSalesEmployee(double baseSalesEmployee) {
        this.baseSalesEmployee = baseSalesEmployee;
    }

    @Override
    public double getSalary(int month) {
        return super.getSalary(month)+baseSalesEmployee;
    }
}
class TestEmployee{
    public static void main(String[] args) {
        SalariedEmployee salariedEmployee = new SalariedEmployee("张三",1,4000);
        System.out.println(salariedEmployee.getSalary(2));

        HourlyEmployee hourlyEmployee = new HourlyEmployee("李四",3,40,165);
        System.out.println(hourlyEmployee.getSalary(3));

        SalesEmployee salesEmployee = new SalesEmployee("王五",6,3000,4000);
        System.out.println(salesEmployee.getSalary(9));

        BasePlusSalesEmployee basePlusSalesEmployee = new BasePlusSalesEmployee("杰克",9,3500,1000,2000);
        System.out.println(basePlusSalesEmployee.getSalary(5));

        System.out.println("打印个员工五月的工资:");
        Employee[] employee = new Employee[]{salariedEmployee,hourlyEmployee,salesEmployee,basePlusSalesEmployee};
        for (int i=0;i<employee.length;i++){
            System.out.println(employee[i].getSalary(5));
        }
    }
}

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 这是一个公司雇员分类问题。雇员分为以下两类: 1. employee:这是所有员工总的父类。 ① 属性:员工的姓名,员工的生日月份。 ② 方法:getsalary(int month),根据参数月份来确定工资,如果该月份是该员工的工资发放月份。 ### 回答2: 某公司的员工分为不同的类别,其中最基本的类别是employee。这个类别包括所有员工的属性和方法。其中,员工的姓名和生日月份是每个员工都有的属性,这些属性可以通过对象的实例变量来存储和访问。而getsalary(int month)方法则是计算员工工资的方法,它可以通过参数来确定需要计算的月份。这个方法需要被每个员工具体实现,因为每个员工的薪资计算规则可能不同。 除了employee类别之外,公司还可以根据员工的特殊职能划分出不同的子类别。例如,公司可以创建一个manager类别,这个类别继承于employee类别,但添加了一些特殊的属性和方法,如管理团队成员、制定项目计划等。同理,公司还可以定义技术员工类别,包括软件工程师、测试工程师、数据库工程师等。这些类别都会有一些特定的属性和方法,比如开发软件、测试软件、优化数据库等。 在创建不同的员工类别时,需要考虑到员工之间的相似性和差异性。相似性表现在员工共同具有的属性和方法上,这些属性和方法应该归属于employee类别中。而不同之处则应该放在不同的子类别中,以便更好地管理和维护。同时,为了实现类别之间的相互关系,需要使用继承、封装、多态等面向对象的编程概念。 总之,划分不同的员工类别有助于企业管理和开发。通过定义不同的类别和方法,可以更加精细地控制企业的运营和发展。同时,这也是面向对象编程和软件设计中重要的概念之一。 ### 回答3: 某公司的员工可以分为以下几类:employee(员工),manager(经理)和CEO(首席执行官)。 首先是employee,他们是所有员工的总父类,拥有两个共同的属性:姓名和生日月份。此外,employee还有一个方法:getsalary(int month),根据传入的月份参数来确定该月的工资。如果员工在该月没有出勤,则不会获得工资。 其次是manager,他们是拥有下属的员工,因此除了拥有employee的属性和方法外,他们还有两个额外属性:下属列表和每日工作小时数。下属列表用于存储其管理的员工,每日工作小时数用于计算其每月的工资。 最后是CEO,他们是公司的最高领导,因此具有employee和manager的所有属性和方法。此外,他们还有一项特殊的权力:可以直接决定公司的财政预算,并决定每个部门(包括自己的部门)的薪资预算,同时还可以通过公司绩效来调整奖金。 综上所述,某公司的员工可以根据职位分为employee、manager和CEO三种类型,每种类型都有其特定的属性和方法,从而满足不同职位的需求和要求。通过这种分类,公司可以更好地管理和激励员工,从而促进公司的发展和成长。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MaGgIeOo0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值