定义一个接口Compute含有一个方法int computer(int n,int m); 设计四个类分别实现此接口,完成+-*/运算 设计一个类UseCompute,含有方法: p
Posted 刘某人丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了定义一个接口Compute含有一个方法int computer(int n,int m); 设计四个类分别实现此接口,完成+-*/运算 设计一个类UseCompute,含有方法: p相关的知识,希望对你有一定的参考价值。
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); } }
以上是关于定义一个接口Compute含有一个方法int computer(int n,int m); 设计四个类分别实现此接口,完成+-*/运算 设计一个类UseCompute,含有方法: p的主要内容,如果未能解决你的问题,请参考以下文章