策略模式 项目中可能用到简单的要求
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) );
}
}
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) );
}
}
相关文章推荐
- 项目中用到的设计模式-策略模式
- Session用法案例 -->实现简单购物车功能(实际项目可能不会这么使用)
- 从真实项目中抠出来的设计模式——第一篇:策略模式
- 设计模式之PHP项目应用——策略模式设计商场收银系统
- Swift 项目中可能用到的第三方框架
- 使用策略模式进行简单的form验证
- 设计模式学习笔记一 简单工厂策略模式实现销售策略的变更(一)
- 策略模式和简单工厂(四)
- 大话设计模式之策略模式(结合简单工厂),程序完善过程蕴含智慧
- 结合项目实例 回顾传统设计模式(四)工厂模式(简单工厂、普通工厂、抽象工厂)
- 策略模式与简单工厂的C++实现
- 策略模式结合简单工厂模式
- 当前项目可能用到的网址
- 简单工厂模式和策略模式
- 简单工厂模式和策略模式的区别
- 策略模式(简单入门)
- 简单工厂、工厂方法、抽象工厂、策略模式、策略与工厂的区别
- BI项目简单备份策略
- 简单工厂模式和策略模式的区别
- 补充策略模式结构图以及简单工厂模式结构图对比