zoukankan      html  css  js  c++  java
  • 练习写一个工资结算系统

    要求:公司将职员分为三类:部门经理、技术员和销售员。在发工资的时候,部门经理拿固定月薪8000元,技术人员按每小时100元领取月薪,销售人员按照500元底薪加当月销售额的4%进行提成,设计并实现一个工资结算系统。

    思路:先创建一个所有员工共有属性和方法的员工类,在创建继承了员工类的经理、技术员和销售员子类,实现调用一种方法就能根据类得到不同结果。

    代码如下:

    package mt.wage;
    /**
     * 员工类
     * @author mt
     *
     */
    public abstract class Employee {
    	protected String name;
    	protected String pasition;
    	
    	
    	public abstract int getSalary() ;
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public String getDepartment() {
    		return pasition;
    	}
    
    	public void setDepartment(String department) {
    		this.pasition = department;
    	}
    	
    	
    }
    
    
    package mt.wage;
    /**
     * 经理类
     * @author mt
     *
     */
    public class Manager extends Employee {
    	public Manager(String name) {
    		this .name = name;
    		this.pasition = "经理";
    	}
    	@Override
    	public int getSalary() {	
    		return 8000;
    	}
    }
    
    package mt.wage;
    /**
     * 技术员类
     * @author mt
     *
     */
    public class Programmer extends Employee {
    	private int workTime;
    	
    	public Programmer(String name , int workTime) {
    		this.name = name;
    		this.workTime = workTime;
    		this.pasition = "技术员";
    	}
    	
    	public int getWorkTime() {
    		return workTime;
    	}
    	public void setWorkTime(int workTime) {
    		this.workTime = workTime;
    	}
    
    	@Override
    	public int getSalary() {
    		return 100 * workTime;
    	}
    
    }
    
    
    package mt.wage;
    /**
     * 销售员类
     * @author mt
     *
     */
    public class Salesman extends Employee {
    	private int sales;
    	
    	public Salesman(String name ,int sales) {
    		this.name = name;
    		this.sales = sales;
    		this.pasition = "销售员";
    	}
    	@Override
    	public int getSalary() {
    		return 1200 + sales * 5/100;
    	}
    
    }
    
    
    package mt.wage;
    
    public class Test {
    	public static void main(String[] args) {
    		Employee[] em ={
    				new Manager("张三"),
    				new Programmer("李斯", 100),
    				new Salesman("王五", 5000),
    				new Programmer("赵钱", 50),
    				new Salesman("孙犁", 10000),
    				new Salesman("麻子", 8000)
    				
    		};
    		for (Employee x :em) {
    		System.out.println(x.pasition + x.name 
    				+ "的"+ "工资为:" + x.getSalary());
    		}
    	}
    }
    
    

  • 相关阅读:
    一起学编程(3--组织与表达)
    摩托罗拉SE955 One Discrete Length,Two Discrete Lengths,Length Within Range 相关解释
    完好用户体验: 活用window.location与window.open解决页面跳转问题
    一张图帮你看懂 iPhone 6 Plus 的屏幕分辨率
    李振杰:火狐Mozilla被黑事件的启发
    POJ 1611 The Suspects 并查集 Union Find
    hdu1879 继续畅通project(最小生成树)
    【Android实战】Socket消息通信
    HDOJ 5098 Smart Software Installer 拓扑排序
    各大电商的缓存策略
  • 原文地址:https://www.cnblogs.com/mt1500/p/4486310.html
Copyright © 2011-2022 走看看