装饰模式实例复杂的奖金计算

复杂的奖金计算

奖金分类,对于个人有当月奖金、个人累计奖金、个人业务增长奖金、及时回款奖金、限时成交加码奖金等;对于业务主管或者是业务经理,除了个人奖金外,还有团队累积奖金、团队业务增长奖金、团队盈利奖金等。

计算公式也有不同

计算奖金金额的基数也有不同

奖金的计算方式会经常变化。要适于调整和修改
在这里插入图片描述
成员接口

package A;
 
public abstract class Component {
 
public abstract double pay();
 
}

人,两个属性在,职务和姓名

package A;
 
public class Person extends Component {
 
	private String name;
	private String position;
	
	public Person() {
	}
 
	public Person(String name, String position) {
		
		this.name = name;
		this.position = position;
	}
   
	public double pay() {
		System.out.print(position+name+"累计奖金为");
		return 0;
	}
 
}

奖金的装饰类

package A;
 
public class Wage extends Component {
 
	protected Component component;
	public void Decorator(Component component)
	{this.component=component;
 
}
	public double pay()
	{if(component!=null)
		return component.pay();
	else
		return 0;
	}
}

当月奖金,一个属性,奖金数额

package A;
 
public class Month extends Wage {
private double money;
 
public Month() {
	
}
 
public Month(double money) {
	
	this.money = money;
}
 
public double pay()//月奖金
{System.out.print("月奖金 "+money+"元 ");
	return super.pay()+money;
}
}

业务增长奖金,一个 属性,业务增长额,计算公式为业务增长额乘0.2

package A;
 
public class Increase extends Wage{
	private double yewue;
	
	public Increase() {
	
	}
 
	public Increase(double yewue) {
	
		this.yewue = yewue;
	}
 
	public double pay()
	{System.out.print("个人业务增长奖金 "+yewue*0.2+"元 ");
	return super.pay()+yewue*0.2;
	}
}

团队奖金一个属性,奖金额

package A;
 
public class Team extends Wage {
	private double money;
	
public Team() {
		
	}
 
public Team(double money) {
	
		this.money = money;
	}
 
public double pay()
{System.out.print("团队增长奖金"+money+"元 ");
return super.pay()+money;
}
}

团队增长奖金,一个属性,增长值,公式为增长值乘0.5

package A;
 
public class TeamIncrease extends Wage {
	private double zengzhang;
	
public TeamIncrease() {
		
	}
 
public TeamIncrease(double zengzhang) {
		
		this.zengzhang = zengzhang;
	}
 
public double pay()
{System.out.print("团队增长奖金"+zengzhang*0.5+"元 ");
return super.pay()+zengzhang*0.5;
}
}

测试

package A;
 
public class Test {
public static void main(String args[])
{Person xc=new Person("小李","程序员");
Person xd=new Person("老王","团队经理");
Month mo=new Month(3000);
Increase in=new Increase(1500);
mo.Decorator(xc);
in.Decorator(mo);
Team tm=new Team(5000);
TeamIncrease ti=new TeamIncrease(2000);
tm.Decorator(xd);
ti.Decorator(tm);
System.out.println(in.pay()+"元");
System.out.println(ti.pay()+"元");
}
}
posted @ 2022-11-21 18:56  TwcatL_tree  阅读(28)  评论(0编辑  收藏  举报