package common;
public enum PayrollDay {
MONDAY(PayType.WEEKDAY), TUESDAY(PayType.WEEKDAY), WEDNESDAY(
PayType.WEEKDAY), THURSDAY(PayType.WEEKDAY), FRIDAY(PayType.WEEKDAY), SATURDAY(
PayType.WEEKDAY), SUNDAY(PayType.WEEKDAY);
private final PayType type;
private PayrollDay(PayType type) {
this.type = type;
}
double pay(double hours,double rate) {
return type.pay(hours, rate);
}
// 枚举策略
private enum PayType {
WEEKDAY {
double overtimePay(double hours, double rate) {
return hours <= HOURS_PER_SHIFT ? 0 : (hours - HOURS_PER_SHIFT)
* rate / 2;
}
},
WEEEND {
double overtimePay(double hours, double rate) {
return hours * rate / 2;
}
};
private static final int HOURS_PER_SHIFT = 8;
abstract double overtimePay(double hours, double rate);
double pay(double hours, double rate) {
double basePay = hours * rate;
return basePay + overtimePay(hours, rate);
}
}
}
策略枚举
最新推荐文章于 2023-11-11 19:50:21 发布