zoukankan      html  css  js  c++  java
  • Java作业5.17

    package mmm;
    
    public class ColaEmployee {
    	String name;
    	int month;
    
    	public ColaEmployee() {
    
    	}
    
    	public ColaEmployee(String name, int month) {
    		super();
    		this.name = name;
    		this.month = month;
    	}
    
    	public double getSalary(int month) {
    		return 0;
    	}
    }
    package mmm;
    
    public class SalariedEmployee extends ColaEmployee {
    	  double n;
    
    	    public SalariedEmployee(String name, int month, double n) {
    	        super(name, month);
    	        this.n = n;
    	    }
    
    	    public double getSalary(int month) {
    	        if (super.month == month) {
    	            return n + 100;
    	        } else {
    	            return n;
    	        }
    	    }
    
    	}
    package mmm;
    
    public class HourlyEmployee extends ColaEmployee {
    	private int a;
    	private int b;
    
    	public HourlyEmployee(String name1, int month, int a1, int b1) {
    		super();
    		this.name=name1;
    		this.b = b1;
    		this.a = a1;
    	}
    
    	public double getSalary(int month) {
    		if (super.month == month) {
    			if (b > 160) {
    				return a * 160 + a * (b - 160) * 1.5 + 100;
    			} else {
    				return a + b + 100;
    			}
    		} else {
    			if (b > 160) {
    				return a * 160 + a * (a - 160) * 1.5;
    			} else {
    				return a * b;
    			}
    		}
    	}
    
    }
    package mmm;
    
    public class SalesEmployee extends ColaEmployee {
    	private int yx;
    	private double m;
    
    	public SalesEmployee(String name, int month, int yx, double m) {
    		super(name, month);
    		this.yx = yx;
    		this.m = m;
    	}
    
    	public double getSalary(int month) {
    		if (super.month == month) {
    			return yx * m + 100;
    		} else {
    			return yx * m;
    		}
    	}
    
    }
    package mmm;
    
    public class Company {
    	 public void getSalary(ColaEmployee c, int month) {
    	        System.out.println(c.name + " 在" + month + "月的月工资数额为 " + c.getSalary(month) + "元");
    	    }
    }
    package mmm;
    
    public class TextCompany {
    
    	public static void main(String[] args) {
    	        ColaEmployee[] m = { new SalariedEmployee("固定员工", 4, 100), new HourlyEmployee("小时工",8,300,100),
    	                new SalesEmployee("销售额和提成的", 4, 2000, 0.3) };
    	        for (int i = 0; i < m.length; i++) {
    	            new Company().getSalary(m[i], 10);
    	        }
    	    }
    
    }
    

      

      

  • 相关阅读:
    三种省市级联下拉列表的写法
    三种省市级联下拉列表的写法
    SQL经典试题(mysql)
    60行代码俄罗斯方块
    ibatis xml中配置信息详解
    60行代码俄罗斯方块
    xinetd
    csh and tcsh
    xinetd restart
    bash sh
  • 原文地址:https://www.cnblogs.com/hzpiou/p/12918817.html
Copyright © 2011-2022 走看看