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);
            }
        }
    
    }

  • 相关阅读:
    java基础之final
    java基础之finally(转)
    java 中 == 与 equals 的区别
    转载:日志分析
    eclipse配置Git
    Gitlab使用笔记:新建工程
    hadoop,spark的启动及DataNode无法启动的解决方法
    HTTP Status 500
    springmvc4.0配置ajax请求json格式数据
    jq load()方法中加载文件中元素事件绑定失效的问题
  • 原文地址:https://www.cnblogs.com/yunlan/p/12901469.html
Copyright © 2011-2022 走看看