zoukankan      html  css  js  c++  java
  • 第十一次作业

    4、Cola公司的雇员分为以下若干类:(知识点:多态)

    (1) ColaEmployee :这是所有员工总的父类,属性:员工的姓名,员工的生日月份。

    • 方法:getSalary(int month) 根据参数月份来确定工资,如果该月员工过生日,则公司会额外奖励100 元。

    (2) SalariedEmployee :     ColaEmployee 的子类,拿固定工资的员工。

    • 属性:月薪

    (3) HourlyEmployee :ColaEmployee 的子类,按小时拿工资的员工,每月工作超出160 小时的部分按照1.5 倍工资发放。

    • 属性:每小时的工资、每月工作的小时数

    (4) SalesEmployee :ColaEmployee 的子类,销售人员,工资由月销售额和提成率决定。

    • 属性:月销售额、提成率

    (5) 定义一个类Company,在该类中写一个方法,调用该方法可以打印出某月某个员工的工资数额,写一个测试类TestCompany,在main方法,把若干各种类型的员工放在一个ColaEmployee 数组里,并单元出数组中每个员工当月的工资。

    private String name;
        private int birmonth;
     
        public void getSalary(int month) {
            System.out.println("month:"+month);
    }
    private double monthsalary;
    private int month;
     
    public void salarySalariedEmployee(String name, int workmonth, int birmonth, double monthsalary) {
        if (workmonth == birmonth) {
            System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + (monthsalary * workmonth + 100));
        } else {
            System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + monthsalary * workmonth);
        }
    }
    private double hoursalary;
    private int monthhour;
     
    public void salaryHourlyEmployee(String name, int birmonth, int workmonth, double hoursalary, int monthhour) {
        if (monthhour > 160) {
            if (workmonth == birmonth) {
                double sumsalary = (monthhour * workmonth - 160) * hoursalary * 1.5 + 160 * hoursalary + 100;
                System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
            } else {
                double sumsalary = (monthhour * workmonth - 160) * hoursalary * 1.5 + 160 * hoursalary;
                System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
            }
        } else {
            if (workmonth == birmonth) {
                double sumsalary = monthhour * workmonth * hoursalary + 100;
                System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
            } else {
                double sumsalary = monthhour * workmonth * hoursalary;
                System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
            }
        }
    }
    private double monthsale;
    private double rate;
     
    public void salarySalesEmployee(String name, int birmonth, int workmonth, double monthsale, double rate) {
        if (workmonth == birmonth) {
            double sumsalary = (monthsale * workmonth) * rate + 100;
            System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
        } else {
            double sumsalary = (monthsale * workmonth) * rate;
            System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
        }
     
    }
    public static void show(ColaEmployee ce) {
        if (ce instanceof SalariedEmployee) {
            SalariedEmployee se = (SalariedEmployee) ce;
            se.salarySalariedEmployee("aa", 7, 6, 6700);
        } else if (ce instanceof HourlyEmployee) {
            HourlyEmployee he = (HourlyEmployee) ce;
            he.salaryHourlyEmployee("bb", 6, 6, 15, 180);
        } else if (ce instanceof SalesEmployee) {
            SalesEmployee see = (SalesEmployee) ce;
            see.salarySalesEmployee("cc", 5, 5, 5200, 0.5);
        }
    }
    package homework;
     
    public class TestCompany {
     
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Company C = new Company();
            SalariedEmployee se = new SalariedEmployee();
            C.show(se);
     
            System.out.println("**************************************");
     
            HourlyEmployee he = new HourlyEmployee();
            C.show(he);
     
            System.out.println("**************************************");
     
            SalesEmployee see = new SalesEmployee();
            C.show(see);
     
        }
     
    }
  • 相关阅读:
    Veritas NetBackup™ for OpenStack
    Win 810系统安装软件报错
    Netbackup驱动器常用命令vmoprcmd
    NBU服务端生成证书/客户端获取、更新证书方式/7656、7654、7640、76XX报错处理
    centos7之系统优化方案【转】
    pip的安装、以及使用方法。
    Python模块(导入,内置,自定义,开源)
    数据库的高可用 及 Mycat的引入
    LeetCode 第21题 合并有序链表
    Docker容器技术
  • 原文地址:https://www.cnblogs.com/jiming123/p/12922039.html
Copyright © 2011-2022 走看看