• 2022-06-07
    (X-5-7)已知某企业的采购审批是分级进行的,根据采购金额的不同由不同层次的主管人员来审批,主任可以审批5万元以下(不包括5元)的采购单,副董事长可以审批5万元至10万元(不包括10万元)的采购单,董事长可以审批10万元至50万元(不包括50万元)的采购单,50万元及以上的采购单就需要开会讨论决定。采用职责链设计模式对上述过程进行设计得到的类图如下图所示。[img=813x391]17e44abe460ef53.png[/img]public PurchaseRequest{public double amount;//一个采购的金额public int number;//采购单编号public String purpose;//采购目的}//审批者类class Approver {public Approver() {successor = null;}public void processRequest(PurchaseRequest aRequest) {if( successor!= null){successor.(1);}}public void setSuccessor(Approver aSuccessor) {successor = aSuccessor;}private(2)successor;}class Congress extends Approver {public void processRequest(PurchaseRequest aRequest) {if (aRequest.amount >; 0000) {// 决定是否审批的代码省略}else(3).processRequest(aRequest);}}class Director extends Approver {public void processRequest(PurchaseRequest aRequest) {// 此处代码省略}}class President extends Approver {public void processRequest(PurchaseRequest aRequest) {// 此处代码省略}}class VicePresident extends Approver {public void processRequest PurchaseRequest aRequest){// 此处代码省略}}public class Test {public static void main(String[ args) throws IOException{Congress meeting=new Congress();VicePresident sam= new VicePresident();Director larry= new Director();//构造职责链meeting. setSuccessor(null);sam.setSuccessor((4)) ;tammy.setSuccessor((5));larry.setSuccessor((6 ));//构造一个采购审批请求BufferedReader br= new BufferedReader(new InputStreamReader(System. in));aRequest.amount=Double. parseDouble( br. readLine());(7).processRequest(aRequest);}}
  • 举一反三