JAVA使用面向对象的思想编写一个计算器~

2020-05-08 社会 266阅读
import java.util.*;
public class Test {
public static void main(String[] argv){
Scanner sc = new Scanner(System.in);
double jieguo = 0;
System.out.print("请输入第一个数字:");
double num1 = sc.nextDouble();
System.out.print("\n请输入第二个数字:");
double num2 = sc.nextDouble();
System.out.print("\n请输入运算符号:");
String fuhao = sc.next();
jisuan js = new jisuan();

if(fuhao.equals("+")){
jieguo = js.jiafa(num1,num2);
System.out.println(jieguo);
}else if(fuhao.equals("-")){
jieguo = js.jiafa(num1, num2);
System.out.println(jieguo);
}else if(fuhao.equals("*")){
jieguo = js.chengfa(num1, num2);
System.out.println(jieguo);
}else if(fuhao.equals("/")){
jieguo = js.chufa(num1, num2);
System.out.println(jieguo);
}else{
System.out.println("您输入的符号不存在");
}
}
}
class jisuan{
public double jiafa(double num1,double num2){
double jieguo = num1+num2;
return jieguo;
}
public double jianfa(double num1,double num2){
double jieguo = num1+num2;
return jieguo;
}
public double chengfa(double num1,double num2){
double jieguo = num1+num2;
return jieguo;
}
public double chufa(double num1,double num2){
double jieguo = num1+num2;
return jieguo;
}
}
如果你还需要封装属性的话.. 请百度Hi我...我会继续的给你搞定...
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com