zoukankan      html  css  js  c++  java
  • java第十一周课后作业05/16

    1.            ColaEmployee父类

    	private String name;
    	private int birmonth;
    
    	public void getSalary(int month) {
    		System.out.println("month:"+month);
    }
    

           SalariedEmployee子类

    	private double monthsalary;
    	private int month;
    
    	public void salarySalariedEmployee(String name, int workmonth, int birmonth, double monthsalary) {
    		if (workmonth == birmonth) {
    			System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + (monthsalary * workmonth + 100));
    		} else {
    			System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + monthsalary * workmonth);
    		}
    	}
    

            HourlyEmployee子类

    	private double hoursalary;
    	private int monthhour;
    
    	public void salaryHourlyEmployee(String name, int birmonth, int workmonth, double hoursalary, int monthhour) {
    		if (monthhour > 160) {
    			if (workmonth == birmonth) {
    				double sumsalary = (monthhour * workmonth - 160) * hoursalary * 1.5 + 160 * hoursalary + 100;
    				System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
    			} else {
    				double sumsalary = (monthhour * workmonth - 160) * hoursalary * 1.5 + 160 * hoursalary;
    				System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
    			}
    		} else {
    			if (workmonth == birmonth) {
    				double sumsalary = monthhour * workmonth * hoursalary + 100;
    				System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
    			} else {
    				double sumsalary = monthhour * workmonth * hoursalary;
    				System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
    			}
    		}
    	}
    

              SalesEmployee子类

    	private double monthsale;
    	private double rate;
    
    	public void salarySalesEmployee(String name, int birmonth, int workmonth, double monthsale, double rate) {
    		if (workmonth == birmonth) {
    			double sumsalary = (monthsale * workmonth) * rate + 100;
    			System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
    		} else {
    			double sumsalary = (monthsale * workmonth) * rate;
    			System.out.println("name:" + name + ",birmonth:" + birmonth + ",sumSalary:" + sumsalary);
    		}
    
    	}
    

           Company类

    	public static void show(ColaEmployee ce) {
    		if (ce instanceof SalariedEmployee) {
    			SalariedEmployee se = (SalariedEmployee) ce;
    			se.salarySalariedEmployee("张三", 6, 6, 6700);
    		} else if (ce instanceof HourlyEmployee) {
    			HourlyEmployee he = (HourlyEmployee) ce;
    			he.salaryHourlyEmployee("李四", 5, 6, 15, 180);
    		} else if (ce instanceof SalesEmployee) {
    			SalesEmployee see = (SalesEmployee) ce;
    			see.salarySalesEmployee("王五", 7, 5, 5200, 0.5);
    		}
    	}
    

       测试类

    package homework;
    
    public class TestCompany {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Company C = new Company();
    		SalariedEmployee se = new SalariedEmployee();
    		C.show(se);
    
    		System.out.println("======================================");
    
    		HourlyEmployee he = new HourlyEmployee();
    		C.show(he);
    
    		System.out.println("======================================");
    
    		SalesEmployee see = new SalesEmployee();
    		C.show(see);
    
    	}
    
    }
    

      

  • 相关阅读:
    C#编程(七十九)---------- 反射
    C#编程(七十一)---------- 自定义特性
    C#编程(七十六)----------使用指针实现基于栈的高性能数组
    C#编程(七十五)----------C#使用指针
    微信开发之移动手机WEB页面(HTML5)Javascript实现一键拨号及短信发送功能
    [asp.net]c# winform打印类
    Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file
    ValueError: invalid literal for int() with base 10: 'abc'
    检查网址是否正常访问
    Python测试网络连通性示例【基于ping】
  • 原文地址:https://www.cnblogs.com/lilbetter03/p/12898215.html
Copyright © 2011-2022 走看看