1 Star 0 Fork 2

北城/GitBash-Calculator_1

forked from czldl/GitBash-Calculator 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Calculator.java 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
北城 提交于 2022-09-28 14:29 . Div
import java.util.Scanner;
interface ICalculate{
int calculate(int m,int n);
}
class Calculate{
public void doCalculate(ICalculate cal,int a,int b){
cal.calculate(a,b);
}
}
class Add implements ICalculate{
private int result;
public int calculate(int m,int n){
result=m+n;
System.out.println(m+"+"+n+"="+result);
return result;
}
}
class Sub implements ICalculate{
private int result;
public int calculate(int m,int n){
result=m-n;
System.out.println(m+"-"+n+"="+result);
return result;
}
}
class Mul implements ICalculate{
private int result;
public int calculate(int m,int n){
result=m*n;
System.out.println(m+"*"+n+"="+result);
return result;
}
}
class Div implements ICalculate{
private int result;
public int calculate(int m,int n){
result=m/n;
System.out.println(m+"/"+n+"="+result);
return result;
}
}
public class Calculator {
public static void main(String[] args) {
int op1;
int op2;
Scanner sc = new Scanner(System.in);
System.out.println("Please input first Number:");
op1=sc.nextInt();
System.out.println("Please input second Number:");
op2=sc.nextInt();
System.out.print("Add Sub Mul Div Resultes:\n");
Calculate cal=new Calculate();
cal.doCalculate(new Add(),op1,op2);
cal.doCalculate(new Sub(),op1,op2);
cal.doCalculate(new Mul(),op1,op2);
cal.doCalculate(new Div(),op1,op2);
sc.close();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/beicheng520/git-bash-calculator_1.git
[email protected]:beicheng520/git-bash-calculator_1.git
beicheng520
git-bash-calculator_1
GitBash-Calculator_1
master

搜索帮助