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