public class Calculator {
Double x;
/*
* Chops up input on ' ' then decides whether to add or multiply.
* If the string does not contain a valid format returns null.
*/
public Double x(String x){
x.split(" ");
return new Double(0);
}
/*
* Adds the parameter x to the instance variable x and returns the answer as a Double.
*/
public Double x(Double x){
System.out.println("== Adding ==");
if (x(1).equals("+")){
x = x(0) + x(2);
}
return new Double(0);
}
/*
* Multiplies the parameter x by instance variable x and return the value as a Double.
*/
public Double x(double x){
System.out.println("== Multiplying ==");
if(x(1).equals("x")){
x = x(0) * x(2);
}
return new Double(0);
}
}
我试图拆分双输入(“12 + 5”)使用“”拆分它,然后根据第二个值使其成为 + 或 x,然后添加或乘以结果。以为我可以通过拆分和时间/添加来做到这一点,但不起作用。