• Lesson_10 作业计算工资


    /**
     * 一家公司按星期支付员工的工资。
     *     该公司有四种员工:
     *         拿薪水的 : 每个星期发给他固定的工资,而不计他们的工作小时数;
     *         钟  点 工: 按小时算,没有加班费;
     *         代  理 人: 按销售业绩按一定的比例抽取佣金.
     *         拿薪代理人: 报酬为基本工资 + 销售额的一定比例的佣金。
     *                    本月公司决定为拿薪金的代理增加10%的基本工资。
     *     公司希望写一个Java程序来动态的计算工资。
     * @author CocoonFan
     *
     */
    public class CalcSalary {
        public static void main(String[] args) {
            CalculateSalary calculateSalary = new CalculateSalary();
            
            BaseSalaryWorker baseSalaryWorker = new BaseSalaryWorker("拿薪水的", 5000);
            calculateSalary.calcSalary(baseSalaryWorker);
            
            HourWorker hourWorker = new HourWorker("钟点工", 0, 300, 15);
            calculateSalary.calcSalary(hourWorker);
            
            ResultsWorker resultsWorker = new ResultsWorker("代理人", 0, 35000, 0.2);
            calculateSalary.calcSalary(resultsWorker);
            
            AgentWorker agentWorker = new AgentWorker("拿薪代理人", 3000, 40000, 0.15);
            calculateSalary.calcSalary(agentWorker);
            
        }
    }
    
    class Worker{
        private String workerName;//
        private double baseSalary = 3000.0;//基本工资
        
        public Worker(String workerName, double baseSalary) {
            this.workerName = workerName;
            this.baseSalary = baseSalary;
        }
        
        public String getWorkerName() {
            return workerName;
        }
        public void setWorkerName(String workerName) {
            this.workerName = workerName;
        }
        public double getBaseSalary() {
            return baseSalary;
        }
        public void setBaseSalary(double baseSalary) {
            this.baseSalary = baseSalary;
        }
        
        public void calcSalary(Worker worker){
            System.out.println("计算工资");
        }
        
    }
    
    class BaseSalaryWorker extends Worker{
    
        public BaseSalaryWorker(String workerName, double baseSalary) {
            super(workerName, baseSalary);
        }
        
        public void calcSalary(Worker worker){
            System.out.println(super.getWorkerName() + "本月工资为:" + super.getBaseSalary());
        }
    }
    
    class HourWorker extends Worker{
        private int workHour;
        private double salaryPerHour;
        public HourWorker(String workerName, double baseSalary, int workHour,double salaryPerHour) {
            super(workerName, baseSalary);
            this.workHour = workHour;
            this.salaryPerHour = salaryPerHour;
        }
        
        @Override
        public void calcSalary(Worker worker){
            System.out.println(super.getWorkerName() + "本月工资为:" + workHour*salaryPerHour);
        }
    }
    
    class ResultsWorker extends Worker{
        private double results;//业绩
        private double ratio;//比例
        
        public ResultsWorker(String workerName, double baseSalary,double results,double ratio) {
            super(workerName, baseSalary);
            this.results = results;
            this.ratio = ratio;
        }
        
        @Override
        public void calcSalary(Worker worker){
            System.out.println(super.getWorkerName() + "本月工资为:" + results*ratio);
        }
        
    }
    
    class AgentWorker extends Worker{
        private double results;//业绩
        private double ratio;//比例
        
        public AgentWorker(String workerName, double baseSalary,double results,double ratio) {
            super(workerName, baseSalary);
            this.results = results;
            this.ratio = ratio;
        }
        
        @Override
        public void calcSalary(Worker worker){
            System.out.println(super.getWorkerName() + "本月工资为:"
                    + (results*ratio + super.getBaseSalary()*1.1));
        }
    }
    
    class CalculateSalary {
        
        public void calcSalary(Worker worker){
            System.out.println("正在计算工资...");
            worker.calcSalary(worker);
            System.out.println();
        }
    }

    运行结果

     

  • 相关阅读:
    【前端大神面考面试官系列】入门Vue全家桶
    【综合篇】浏览器的工作原理:浏览器幕后揭秘
    【星云测试】开发者测试(2)-采用精准测试工具对J2EE Guns开发框架进行测试
    【星云测试】开发者测试(3)-采用精准测试工具对springcloud微服务应用进行穿透测试
    【星云测试】开发者测试(4)-采用精准测试工具对dubbo微服务应用进行测试
    【星云测试】精准测试的软件产品质量效率变化分析
    巧用location.hash保存页面状态
    全面解析ASP.NET MVC模块化架构方案
    在多线程编程中lock(string){...}隐藏的机关
    注释是恶魔,请不要再写一行注释
  • 原文地址:https://www.cnblogs.com/CocoonFan/p/2870662.html
Copyright © 2020-2023  润新知