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();
    }
}
Client
package shiyan14;

public interface People {
    public void setAge(int Age);
    public void lovers();
}
People
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();
        }
    }
}
Proxy
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("已为您匹配到最佳伴侣");
    }
}
Real

 

实验15

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);
        }
    }

}
Bumen
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);

    }
}
Client
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);
        }
    }

}
Fuzong
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);
}
Leader
package shiyan15;

public class Order {
    private double money;
    public double getMoney(){
        return money;
    }
    public void setMoney(double a){
        money=a;
    }
}
Order
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);
        }
    }

}
Zhuren
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()+"元的采购单"+"需要职工大会确定");
        }
    }

}
Zong

 

posted on 2023-11-16 08:47  夜的第七章i  阅读(5)  评论(0编辑  收藏  举报