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

    1.

    package test;
    
    public class ColaEmployee {
        String name;
        int month;
        
        public ColaEmployee() {
            super();
            
        }
        
    
        public ColaEmployee(String name, int month) {
            super();
            this.name = name;
            this.month = month;
        }
    
    
        public double getSalary(int month){    
            return month;
        }
    
    }

    2.

    package test;
    
    public class SalariedEmployee extends ColaEmployee {
        double monthsalary ;
    
        public SalariedEmployee() {
            super();
            
        }
    
        public SalariedEmployee(String name, int mouth ,double monthsalary) {
            super(name, mouth);
            this.monthsalary = monthsalary;
            
        }
        @Override
        public double getSalary(int month) {
             
                if (super.month == month) {
                    return monthsalary + 100;
                } else {
                    return monthsalary;
                }
    
            }
        
    
    }

    3.

    package test;
    
    public class HourlyEmployee extends ColaEmployee {
        int hourSalary;
        int hour;
    
        public HourlyEmployee() {
            super();
        }
    
        public HourlyEmployee(String name, int month, int hourSalary, int hour) {
            super(name, month);
            this.hourSalary = hourSalary;
            this.hour = hour;
        }
        @Override
    
        public double getSalary(int month) {
            if(super.month == month){
                if (hour > 160) {
                    return hourSalary * 160+ (hour-160)*1.5*hourSalary + 100;
                } else {
                    return hourSalary * hour + 100;
                }
            }else{
                if (hour > 160) {
                    return hourSalary * 160 +(hour - 160)*1.5*hourSalary  ;
                } else {
                    return hourSalary * hour;
                }
                
            }
            
    
    
         
        }
       
    
    }

    4.

    package test;
    
    public class SalesEmployee extends ColaEmployee {
        double monthsalary;
        double monthcommission ;
        public SalesEmployee() {
            super();
        }
        public SalesEmployee(String name,int month,double monthsalary, double monthcommission) {
            super(name,month);
            this.monthsalary = monthsalary;
            this.monthcommission = monthcommission;
        }
        @Override
        public double getSalary(int month) {
            if (super.month == month) {
                return monthsalary*monthcommission + 100;
            } else {
                return monthsalary*monthcommission;
            }
    
        }
    
        
        
    
    }

    5.

    package test;
    
    public class Company {
        public void getSalary(ColaEmployee c, int month) {
            System.out.println(c.name + "在" + month + "月的月薪是:" + c.getSalary(month) + "元");
        }
    
    }

    6.

    package test;
    
    public class TestCompany {
    
        public static void main(String[] args) {
            ColaEmployee[] cel = {
                    new SalariedEmployee("按月数计算的员工", 5, 5000),
                    new HourlyEmployee("按天数计算的员工", 10, 300,70),
                    new SalesEmployee("按小时计算的员工", 15, 50, 100)
                    };
            for (int i = 0; i < cel.length; i++) {
                new Company().getSalary(cel[i],3);
            }
            
            
        }
    
    }
  • 相关阅读:
    取出某块内存的二进制数据
    拷贝构造函数的第一个参数必须是自身类类型的引用
    大小端,memcpy和构造函数
    类型装换和内存数据显示
    ERROR: iterator not incrementable || iterator not decrementable
    什么时候删除指针后,要给指针赋NULL
    chapter11、4concurrent.future模块
    chapter11、3多进程 multiprocessing
    chapter8.3、二分查找
    chapter8.2、面向对象三要素--继承
  • 原文地址:https://www.cnblogs.com/z118127/p/12922674.html
Copyright © 2011-2022 走看看