某航空公司的会员积分系统将其会员划分为:普卡(Basic)、银卡(Silver)和金卡(Gold)
三个等级。非会员(Non Member)可以申请成为普卡会员。会员的等级根据其一年内累积的里程数进行调整。描述会员等级调整的状态图如图6-1所示。现采用状态(State)模式
实现上述场景,得到如图6-2所示的类图。


正确答案及解析
正确答案
解析
(1)abstract double travel(int miles,FrequentFlyer context)
(2)context.setState(new CSilver())
(3)context.setState(new CGold())
(4)context.setState(new CSilver())
(5)context.setState(new CBasic())
由代码可知,(1)空缺少一个抽象方法,根据下面的子类可以发现,子类都有double travel(int miles,FrequentFlyer context)方法,是从该抽象类中继承而来,因此(1)空应该补充这个方法,并加上abstract修饰。
(2)(3)(4)(5)可以从状态图中根据相关状态推断出来。
首先,(2)(3)属于普卡会员CBasic,从状态图和代码可以看到,当里程>=25000且<5000时,会员等级应该从普卡会员CBasic升级到银卡会员CSilver,根据后面已有的代码,可以推断表示升级到银卡会员CSilver的表示方式为context.setState(new CSilver());同理对于(3)空,在普卡会员CBasic状态,里程>=50000时,应该升级为金卡会员CGold,此时升级金卡CGold的表示方式为context.setState(new CGold()),以此类推,(4)(5)分别对应金卡会员CGold状态下,不同条件,降低的不同等级。因此(4)为降级为银卡会员CSilver,(5)为降级为普卡会员CBasic,对应的表示方式分别为context.setState(new CSilver())和context.setState(new CBasic())。
包含此试题的试卷
你可能感兴趣的试题
Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.
-
- A.Artificial Intelligence
- B.Cloud Computing
- C.Internet of Things
- D.Big Data
- 查看答案
In project human resource management , ( )is not a source of power for the project manager.
-
- A.referent power
- B.expert power
- C.reward power
- D.audit power
- 查看答案
At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.
-
- A.detail feasibility analysis
- B.opportunity analysis
- C.economic feasibility analysis
- D.risk analysis
- 查看答案
( )is a grid that shows the project resources assigned to each work package.
-
- A.Stakeholder engagement assessment matrix
- B.Requirements traceability matrix
- C.Probability and impact matrix
- D.Responsibility assignment matrix
- 查看答案
Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.
-
- A.digital
- B.networking
- C.intelligentize
- D.informatization
- 查看答案