练习写一个工资结算系统

要求:公司将职员分为三类:部门经理、技术员和销售员。在发工资的时候,部门经理拿固定月薪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());
        }
    }
}

072222063928867.png

转载于:https://www.cnblogs.com/mt1500/p/4486310.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值