![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan14; public class Client { public static void main(String[] args) { Proxy proxy=new Proxy(); Real real=new Real(); real.setAge(30); System.out.println("UZI 30岁"); proxy.setReal(real); proxy.lovers(); real.setAge(6); System.out.println("lwx 6岁"); proxy.setReal(real); proxy.lovers(); } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan14; public interface People { public void setAge(int Age); public void lovers(); }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan14; public class Proxy implements People{ private Real real=new Real(); public void setReal(Real a){ real=a; } public void setAge(int Age){ } public void lovers(){ if(real.getAge()<18){ System.out.println("对不起,您还未满18岁,不能早恋!"); } else{ real.lovers(); } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan14; public class Real implements People{ private int age=0; public void setAge(int Age){ age=Age; } public int getAge(){ return age; } public void lovers(){ System.out.println("已为您匹配到最佳伴侣"); } }
实验15
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public class Bumen extends Leader{ public Bumen(String a) { super(a); } public Bumen(String a,Leader b){ super(a,b); } public void approvel(Order dan) { if(dan.getMoney()<=50000){ System.out.println(name+"同意审批这个"+dan.getMoney()+"元的采购单"); }else { System.out.println(name+"不能审批5万元以上的采购单"); this.successor.approvel(dan); } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public class Client { public static void main(String[] args) { Leader zhuren,bumen,fuzong,zong; Order danzi=new Order(); zong=new Zong("总经理"); fuzong=new Fuzong("副总经理",zong); bumen=new Bumen("部门经理",fuzong); zhuren=new Zhuren("主任",bumen); danzi.setMoney(5000); zhuren.approvel(danzi); System.out.println("--------—----------------------------"); danzi.setMoney(50000); zhuren.approvel(danzi); System.out.println("--------—----------------------------"); danzi.setMoney(1000000); zhuren.approvel(danzi); } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public class Fuzong extends Leader{ public Fuzong(String a) { super(a); } public Fuzong(String a,Leader b){ super(a,b); } public void approvel(Order dan) { if(dan.getMoney()<=100000){ System.out.println(name+"同意审批这个"+dan.getMoney()+"元的采购单"); }else { System.out.println(name+"不能审批10万元以上的采购单"); this.successor.approvel(dan); } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public abstract class Leader { protected String name; protected Leader successor; public Leader(String a){name=a;} public void setSuccessor(Leader a){ successor=a; } public Leader(String a,Leader b){ name=a; successor=b; } public abstract void approvel(Order dan); }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public class Order { private double money; public double getMoney(){ return money; } public void setMoney(double a){ money=a; } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public class Zhuren extends Leader{ public Zhuren(String a) { super(a); } public Zhuren(String a,Leader b){ super(a,b); } public void approvel(Order dan) { if(dan.getMoney()<=10000){ System.out.println(name+"同意审批这个"+dan.getMoney()+"元的采购单"); }else { System.out.println(name+"不能审批1万元以上的采购单"); this.successor.approvel(dan); } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package shiyan15; public class Zong extends Leader{ public Zong(String a) { super(a); } public Zong(String a,Leader b){ super(a,b); } public void approvel(Order dan) { if(dan.getMoney()<=200000){ System.out.println(name+"同意审批这个"+dan.getMoney()+"元的采购单"); }else { System.out.println(name+"不能审批20万元以上的采购单"); System.out.println("这个"+dan.getMoney()+"元的采购单"+"需要职工大会确定"); } } }