您的位置:首页 > 其它

不同类型员工存入数组打印某月工资

2016-12-13 11:16 239 查看
package gongzi;

public class Employee {
/**
* 员工总类
*/
private String name;
private int month;//生日月份

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getMonth() {
return month;
}

public void setMonth(int month) {
this.month = month;
}

public void getSalary(int month){

}

}


package gongzi;
/**
* 固定工资员工
* @author Administrator
*
*/
public class SalariedEmployee extends Employee {
private double money;//固定工资数;

public double getMoney() {
return money;
}

public void setMoney(double money) {
this.money = money;
}

@Override
public void getSalary(int month) {
if(this.getMonth()==month){
System.out.println(this.getName()+""+month+"月份的工资为"+(money+1000)+"元");
}
else{
System.out.println(this.getName()+""+month+"月份的工资为"+money+"元");
}
}


package gongzi;

/**

* 无底薪销售

* @author Administrator

*

*/

public class SalesEmployee extends Employee {

private double money;//月销售额

private double tcl;//提成率

public double getMoney() {
return money;
}

public void setMoney(double money) {
this.money = money;
}

public double getTcl() {
return tcl;
}

public void setTcl(double tcl) {
this.tcl = tcl;
}

@Override
public void getSalary(int month) {
if(this.getMonth() == month){
System.out.println(this.getName()+""+month+"月份的工资为"+(money*tcl+1000)+"元");
}else{
System.out.println(this.getName()+""+month+"月份的工资为"+(money*tcl)+"元");
}
}


package gongzi;
/**
* 小时工
* @author Administrator
*
*/
public class HourlyEmployee extends Employee {
private double money;//每小时工资
private double hour;//每月工作的小时数

public double getMoney() {
return money;
}

public void setMoney(double money) {
this.money = money;
}

public double getHour() {
return hour;
}

public void setHour(double hour) {
this.hour = hour;
}

@Override
public void getSalary(int month) {
double salary=0;
if(hour > 160){
salary = (160*money)+(hour-160)*1.5*money;
}else{
salary = hour*money;
}
if(this.getMonth()==month){
salary+=1000;
}
System.out.println(this.getName()+""+month+"月份的工资为"+salary+"元");
}

}


package gongzi;
/**
* 有底薪销售
* @author Administrator
*
*/
public class BasePlusSalesEmployee extends SalesEmployee {
private double dx;//底薪

public double getDx() {
return dx;
}

public void setDx(double dx) {
this.dx = dx;
}

@Override
public void getSalary(int month) {
if(this.getMonth()==month){
System.out.println(this.getName()+month+"月工资为:"+((dx+this.getMoney())*(this.getTcl()+1000))+"元");
}
else{
System.out.println(this.getName()+month+"月工资为:"+(dx+this.getMoney())*(this.getTcl()+1000)+"元");
}
}

}


package gongzi;
/**
* 测试类
* @author Administrator
*
*/
public class Test {
public static void main(String[] args) {

SalariedEmployee e1=new SalariedEmployee();
e1.setMonth(2);
e1.setName("张三");
e1.setMoney(3000);

HourlyEmployee e2 = new HourlyEmployee();
e2.setMonth(3);
e2.setName("李四");
e2.setMoney(10);
e2.setHour(160);

SalesEmployee e3 = new SalesEmployee();
e3.setMonth(2);
e3.setName("王五");
e3.setMoney(30000);
e3.setTcl(0.1);

BasePlusSalesEmployee e4 = new BasePlusSalesEmployee();
e4.setMonth(4);
e4.setName("赵六");
e4.setMoney(2000);
e4.setTcl(0.1);
e4.setDx(2000);

Employee[] emp={e1,e2,e3,e4};
for (Employee employee : emp) {
employee.getSalary(2);
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐