您的位置:首页 > 其它

策略模式 项目中可能用到简单的要求

2010-12-18 10:45 267 查看
某公司的雇员分为以下若干类:
Employee:这是所有员工总的父类,
属性:员工的姓名和生日月份。
方法:getSalary(int month) 根据参数月份来确定工资,
如果该月员工过生日,则公司会额外奖励100元。

SalariedEmployee:Employee的子类,拿固定工资的员工。
属性:月薪

HourlyEmployee:Employee的子类,按小时拿工资的员工,
每月工作超出160小时的部分按照1.5倍工资发放
属性:每小时的工资、每月工作的小时数

SalesEmployee:Employee的子类,销售人员,工资由月销
售额和提成率决定
属性:月销售额、提成率
1-10万之间,提成率 2%,10-50万,提成率 1.5%;
50-100万之间,提成率 1.2%

BasePlusSalesEmployee:SalesEmployee的子类,有固定底
薪的销售人员,工资由底薪加上销售提成部分
属性:底薪。

了解:Java 设计模式 “策略模式”

public class Test {
public double getHortation1(int month) {
double hortation ;
int temp = month;
int mon = 4;
if( mon == temp)
hortation = 1250.0 + 100;
else
hortation = 1250.0;
return hortation;
}
public double getHortation2(int month, double hours) {
double hortation = 0.0 ;
int mon = 5;
int temp1 = month ;
double temp2 = hours;
if( temp2 > 160.0){
hortation = 160 * 10.0;
hortation = (temp2- 160.0)*10.0 * 1.5;
}
else
hortation = temp2 * 10.0;
if( mon == temp1)
hortation += 100.0;
return hortation;
}
public double getHortation3(int month, double total) {
double hortation = 0.0 ;
int mon = 6;
int temp1 = month ;
double temp2 = total;
if(temp2 < 100000.0)
hortation = temp2 *0.05;
else
if(temp2 >= 100000.0 && temp2 < 500000)
hortation = 100000*0.05 + (temp2 - 100000)*0.1;
else
if(temp2 >= 500000.0 && temp2 < 1000000)
hortation = 100000*0.05 + (500000-100000)*0.1 + (temp2 - 500000)*0.15;
else
hortation = 100000*0.05 + (500000-100000)*0.1 + (1000000 - 500000)*0.15 + (temp2 - 1000000)*0.2;
if( mon == temp1)
hortation += 100.0;
return hortation;
}
public double getHortation4(int month, double basicSalay, double total) {
double hortation = 0.0 ;
int mon = 7;
int temp1 = month ;
double temp2 = 1000.0;
double temp3 = total;
hortation = 1000.0 + total*0.05;
if( mon == temp1)
hortation += 100.0;
return hortation;
}
public static void main(String[] args) {
Test test = new Test();
//拿固定工资的员工
System.out.println("拿固定工资的员工的工资:"+test.getHortation1(4));

//按小时拿工资的员工,每月工作超出160小时的部分按照1.5倍工资发放

System.out.println("按小时拿工资的员工的工资:"+test.getHortation2(4, 100.0));

//工资由月销售额和提成率决定

System.out.println("工资由月销售额和提成率决定的员工的工资:"+test.getHortation3(4, 100000));

//有固定底薪的销售人员,工资由底薪加上销售提成部分

System.out.println("有固定底薪的销售人员的工资::"+test.getHortation4(4, 1200,500000) );
}

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