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);
            }
            
            
        }
    
    }
  • 相关阅读:
    Android布局尺寸思考
    正则表达式五分钟快速复习
    git gitignore文件失效处理
    华为手机Edittext光标(cursor)颜色修改
    AndroidStudio-OSX 常用快捷键整理
    OS X(EI Capitan)常用快捷键整理
    通过Foxit和坚果云实现iPad和PC的pdf同步阅读(修改,笔记)
    《程序员必读的职业规划书》职业生涯规划部分书摘及感想
    以神经网络使用为例的Matlab和Android混合编程
    写出优美代码的两个方式:一步到位VS迭代优化
  • 原文地址:https://www.cnblogs.com/z118127/p/12922674.html
Copyright © 2011-2022 走看看