阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
某大型购物中心欲开发一套收银软件,要求其能够支持购物中心在不同时期推出的各种促销活动,如打折、返利(例如,满300返100)等等。现采用策略(Strategy)模式实现该要求,得到如图6-1所示的类图。
importjavA.util.*;
enumTYPE{
NORMAL,CASH_DISCOUNT,CASH_RETURN};
interface
CashSuper{
public(1);
}
classCashNormal
implementsCashSuper{//正常收费子类
publicdoubleaccptCash(doublemoney){
returnmoney;
}
}
class
CashDiscountimplementsCashSuper{
privatedoublemoneyDiscount;
//折扣率
publicCashDiscount(doublemoneyDiscount){
thismoneyDiscount=moneyDiscount;
}
publicdoubleacceptCash(doublemoney){
returnmoney*moneyDiscount;
}
}
classCashReturn
implementsCashSuper{//满额返利
privatedoublemoneyCondition;
privatedoublemoneyReturn;
publicCashReturn(doublemoneyCondition,doublemoneyReturn){
this.moneyCondition=moneyCondition;//满额数额
this.moneyReturn=moneyReturn;//返利数额
}
publicdoubleacceptCash(doublemoney){
doubleresult=money;
if(money>=moneyCondition)
result=money-Math.floor(money/moneyCondition)*
moneyReturn;
returnresult;
}
}
class
CashContext_{
privateCashSupercs;
privateTYPEt;
publicCashContext(TYPEt){
switch(t){
caseNORMAL://正常收费
(2);
break;
caseCASH_DISCOUNT://满300返100
(3);
break;
caseCASH_RETURN://打8折
(4);
break;
}
}
publicdoubleGetResult(doublemoney){
(5);
}
∥此处略去main()函数
}
(1)double acceptCash(double money) (2)cs = new CashNormal()(3)cs = new CashDiscount(0.8)(4)cs = new CashReturn(300,100)(5)return cs.acceptCash(money)