(1)定义一个接口Compute含有一个方法int computer(int n,int m); (2)设计四个类分别实现此接口,完成+-*/运算 (3)设计一个类UseCompute,含有方法: public void useCom(Compute com, int one, int two) (4)设计一个测试类

package b;

public interface Computer {
    int computer(int n,int m);

}

package b;

public class Jia implements Computer {

    @Override
    public int computer(int n, int m) {
        int jia;
        jia=m+n;
        System.out.println(m+"+"+n+"="+jia);
        return jia;
    }

}

package b;

public class Jian implements Computer {

    @Override
    public int computer(int n, int m) {
        int jian;
        jian=m-n;
        System.out.println(m+"-"+n+"="+jian);
        return jian;
    }

}

 

package b;

public class Jian implements Computer {

    @Override
    public int computer(int n, int m) {
        int jian;
        jian=m-n;
        System.out.println(m+"-"+n+"="+jian);
        return jian;
    }

}

package b;

public class Cheng implements Computer {

    @Override
    public int computer(int n, int m) {
        int cheng;
        cheng=m*n;
        System.out.println(m+"*"+n+"="+cheng);
        return cheng;
    }

}

package b;

public class Chu implements Computer {

    @Override
    public int computer(int n, int m) {
        int chu;
        chu=m/n;
        System.out.println(m+"/"+n+"="+chu);
        return chu;
    }

}

package b;

public class UseComputer implements Computer {

    @Override
    public int computer(int n, int m) {
        
        return 0;
    }
    
    
    public void useCom(Computer com, int n, int m)
    {
        com.computer(n, m);
    }
    

}

package b;

public class TestComputer {

    public static void main(String[] args) {
    UseComputer m=new UseComputer();
    Jia a=new Jia();
    Jian b=new Jian();
    Cheng c=new Cheng();
    Chu d=new Chu();
    m.useCom(a, 3, 5);
    m.useCom(b, 3, 5);
    m.useCom(c, 3, 5);
    m.useCom(d, 3, 5);
    }

}

 

posted @ 2016-05-27 08:47  刘某人丶  阅读(2473)  评论(0编辑  收藏  举报