• 2021/11/25


    public class Client
    {
    	public static void main(String args[])
    	{
    		Leader objDirector,objManager,objGeneralManager,objViceGeneralManager;
    		
    		objDirector=new Director("王明");
    		objManager=new Manager("赵强");
    		objGeneralManager=new GeneralManager("李波");
    		objViceGeneralManager=new ViceGeneralManager("肖红");
    		
    		objDirector.setSuccessor(objManager);
    		objManager.setSuccessor(objViceGeneralManager);
    		objViceGeneralManager.setSuccessor(objGeneralManager);
    			
    		LeaveRequest lr1=new LeaveRequest("张三",5000);
    		objDirector.handleRequest(lr1);
    			
    		LeaveRequest lr2=new LeaveRequest("李四",20000);
    		objDirector.handleRequest(lr2);
    		
    		LeaveRequest lr3=new LeaveRequest("王五",80000);
    		objDirector.handleRequest(lr3);
    						
    		LeaveRequest lr4=new LeaveRequest("赵六",140000);
    		objDirector.handleRequest(lr4);			
    	}
    }
    

      

    public class Director extends Leader
    {
    	public Director(String name)
    	{
    		super(name);
    	}
    	public void handleRequest(LeaveRequest request)
    	{
    		if(request.getLeaveDays()<10000)
    		{
    			System.out.println("主任" + name + "审批" + request.getLeaveName() + "的购物清单,金额为" + request.getLeaveDays() + "元。");
    		}
    		else
    		{
    			if(this.successor!=null)
    			{
    				this.successor.handleRequest(request);
    			}
    		}
    	}
    }
    

      

    public class GeneralManager extends Leader
    {
    	public GeneralManager(String name)
    	{
    		super(name);
    	}
    	
    	public void handleRequest(LeaveRequest request)
    	{
    		if(request.getLeaveDays()<200000)
    		{
    			System.out.println("总经理" + name + "审批" + request.getLeaveName() + "的购物清单,金额为" + request.getLeaveDays() + "元。");
    		}
    		else
    		{
    			System.out.println("总经理没有权限批准");
    		}
    	}
    }
    

      

    public abstract class Leader
    {
    	protected String name;
    	protected Leader successor;
    	public Leader(String name)
    	{
    		this.name=name;
    	}
    	public void setSuccessor(Leader successor)
    	{
    		this.successor=successor;
    	}
    	public abstract void handleRequest(LeaveRequest request);
    }
    

      

    public class LeaveRequest
    {
    	private String leaveName;
    	private int leaveDays;
    	
    	public LeaveRequest(String leaveName,int leaveDays)
    	{
    		this.leaveName=leaveName;
    		this.leaveDays=leaveDays;
    	}
    	
    	public void setLeaveName(String leaveName) {
    		this.leaveName = leaveName; 
    	}
    
    	public void setLeaveDays(int leaveDays) {
    		this.leaveDays = leaveDays; 
    	}
    
    	public String getLeaveName() {
    		return (this.leaveName); 
    	}
    
    	public int getLeaveDays() {
    		return (this.leaveDays); 
    	}	
    }
    

      

    public class Manager extends Leader
    {
    	public Manager(String name)
    	{
    		super(name);
    	}
    	public void handleRequest(LeaveRequest request)
    	{
    		if(request.getLeaveDays()<50000)
    		{
    			System.out.println("部门经理" + name + "审批" + request.getLeaveName() + "的购物清单,金额为" + request.getLeaveDays() + "元。");
    		}
    		else
    		{
    			if(this.successor!=null)
    			{
    				this.successor.handleRequest(request);
    			}
    		}
    	}
    }
    

      

    public class ViceGeneralManager extends Leader
    {
    	public ViceGeneralManager(String name)
    	{
    		super(name);
    	}
    	public void handleRequest(LeaveRequest request)
    	{
    		if(request.getLeaveDays()<100000)
    		{
    			System.out.println("副总经理" + name + "审批" + request.getLeaveName() + "的购物清单,金额为" + request.getLeaveDays() + "元。");
    		}
    		else
    		{
    			if(this.successor!=null)
    			{
    				this.successor.handleRequest(request);
    			}
    		}
    	}
    }
    

      

  • 相关阅读:
    翻转链表——链表
    Hadoop 2.2.0和HBase-0.98 安装snappy
    【POJ 1850】 Code
    Google翻译PDF文档
    leetcode第一刷_Reverse Linked List II
    linux之SQL语句简明教程---AND OR
    spring实战三装配bean之Bean的作用域以及初始化和销毁Bean
    spring实战一:装配bean之注入Bean属性
    系统启动时,spring配置文件解析失败,报”cvc-elt.1: 找不到元素 'beans' 的声明“异常
    阿里云ECS(云服务器)之产品简介
  • 原文地址:https://www.cnblogs.com/qiangini/p/15580433.html
Copyright © 2020-2023  润新知