• 第十一周作业


    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);
            }
            
            
        }
    
    }
  • 相关阅读:
    【LeetCode & 剑指offer刷题】动态规划与贪婪法题13:Coin Change(系列)
    【LeetCode & 剑指offer刷题】动态规划与贪婪法题12:Jump Game(系列)
    【LeetCode & 剑指offer刷题】动态规划与贪婪法题11:121. Best Time to Buy and Sell Stock(系列)
    【LeetCode & 剑指offer刷题】动态规划与贪婪法题10:Longest Increasing Subsequence
    linux安装rabbitmq
    微服务-springboot-读写分离(多数据源切换)
    微服务-springboot-rabbitmq:实现延时队列
    java-NIO-DatagramChannel(UDP)
    java-NIO-FileChannel(文件IO)
    java-NIO-概念
  • 原文地址:https://www.cnblogs.com/z118127/p/12922674.html
Copyright © 2020-2023  润新知