zoukankan      html  css  js  c++  java
  • JAVA-1.9-homework

    package Cola;
    
    public abstract class ColaEmployee {
        String name;
        int birthmonth;
        
        public ColaEmployee() {
            
        }
    
        public ColaEmployee(String name, int birthmonth) {
            this.name = name;
            this.birthmonth = birthmonth;
        }
    
        abstract double getSalary(int month) ;
    }
    package Cola;
    
    public class SalariedEmployee extends ColaEmployee{
        double salar;
        
        public SalariedEmployee() {
            
        }
    
        public SalariedEmployee(String name, int birthmonth,double salar) {
            super(name,birthmonth);
            this.salar=salar;
        }
    
        @Override
         double getSalary(int month) {
            if(month==birthmonth) {
                salar+=100;
            }
            return salar;
        }
    }
    package Cola;
    
    public class HourlyEmployee extends ColaEmployee{
        double shourly;
        double hours;
    
        public HourlyEmployee() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        public HourlyEmployee(String name, int birthmonth,double shourly,double hours) {
            super(name, birthmonth);
            // TODO Auto-generated constructor stub
            this.shourly=hours;
            this.hours=hours;
        }
    
        double getSalary(int month) {
            if(hours>160.0) {
                shourly=(160.0*shourly)+(hours-160.0)*(shourly*1.5);
            }else {
                shourly=hours*shourly;
            }
            if(month==birthmonth) {
                shourly+=100.0;
                return shourly;
            }else {
                return shourly;
            }
        }
    }
    package Cola;
    
    public class SalesEmployee extends ColaEmployee{
        double smonthly;
        double rate;
        
         public SalesEmployee() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        public SalesEmployee(String name, int birthmonth, double smonthly,double rate) {
            super(name, birthmonth);
            // TODO Auto-generated constructor stub
            this.smonthly=smonthly;
            this.rate=rate;
        }
    
        public double getSalary(int month) {
             smonthly=smonthly+smonthly*rate;
             if(month==birthmonth) {
                 smonthly+=100;
                 return smonthly;
             }else {
                 return smonthly;
             }
         }
    }
    package Cola;
    
    public class Company{
        public static void getSalary(ColaEmployee a,int month) {
            System.out.println(month+"月"+a.name+"员工"+"的月薪是"+a.getSalary(month)+"元。");
        }
    }
    package Cola;
    
    public class TestCompany {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            ColaEmployee [] b=new ColaEmployee[6];
            b[0]=new SalesEmployee("王伟", 4, 10000, 5);
            b[1]=new SalesEmployee("刘美",8,12000,5);
            b[2]=new SalariedEmployee("张钧", 11, 20000);
            b[3]=new SalariedEmployee("高晟", 2, 23000);
            b[4]=new HourlyEmployee("季澊", 9, 200, 168);
            b[5]=new HourlyEmployee("沈复",5,300,170);
            for (ColaEmployee a:b) {
                Company.getSalary(a,5);
            }
        }
    
    }

  • 相关阅读:
    【重磅】FineUIPro基础版免费,是时候和ExtJS说再见了!
    【续】抓个Firefox的小辫子,jQuery表示不背这黑锅,Chrome,Edge,IE8-11继续围观中
    FineUICore已发布,跨平台速度快(现在可申请试用)!
    【原创】抓个Firefox的小辫子,围观群众有:Chrome、Edge、IE8-11
    快了快了,你的 MacBook Pro 和 FineUICore!
    [ASP.NET Core 2.0 前方速报]Core 2.0.3 已经支持引用第三方程序集了
    [译]ASP.NET Core 2.0 区域
    [译]ASP.NET Core 2.0 视图组件
    [译]ASP.NET Core 2.0 部分视图
    [译]ASP.NET Core 2.0 布局页面
  • 原文地址:https://www.cnblogs.com/yunlan/p/12901469.html
Copyright © 2011-2022 走看看