MVC开发模式,javabean中函数if分支语句好像不起作用?换成switch-case就正确了,为什么?
javabean中代码:
package javabean;
public class Fs {
private double x;
private double y;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public Fs(double x, double y) {
this.x = x;
this.y = y;
}
public Fs() {}
public Fs opp(Fs c,String op) {
double j = 0;
double i = 0;
switch(op) {
case "+" :
j=this.x+c.x;
i=this.y+c.y;
break;
case "-" :
j=this.x-c.x;
i=this.y-c.y;
break;
case "*" :
j=(this.x*c.x)-(this.y*c.y);
i=(this.y*c.x)+(this.x*c.y);
break;
case "/" :
j=(this.x*c.x+this.y*c.y)/((c.x*c.x)+(c.y*c.y));
i=((this.y*c.x)-(this.x*c.y))/((c.x*c.x)+(c.y*c.y));
break;
}
return new Fs(j,i);
}
public String pp() {
String r=null;
if(y!=0) {
if(y>0)
r=""+x+"+"+y+"i";
else
r=""+x+y+"i";
}
else
r=""+x;
return r;
}
//以下是计算函数的修改过程,错误原因应该都是c3没有正确的调用函数
//在if分支语句好像并不起作用,换成switch-case则正确,原因?
/* 第一版本
public Fs add(Fs c) {
double j=this.x+c.x;
double i=this.y+c.y;
Fs m = new Fs(j,i);
return m;
}
public Fs subtract(Fs c) {
double j=this.x-c.x;
double i=this.y-c.y;
Fs m = new Fs(j,i);
return m;
}
public Fs mutiply(Fs c) {
//(ac-bd)+(bc+ad)i
double j=(this.x*c.x)-(this.y*c.y);
double i=(this.y*c.x)+(this.x*c.y);
Fs m = new Fs(j,i);
return m;
}
public Fs divide(Fs c) {
//(a+bi)/(c+di)=(ac+bd)/(c2+d2) +((bc-ad)/(c2+d2))i
double j=(this.x*c.x+this.y*c.y)/((c.x*c.x)+(c.y*c.y));
double i=((this.y*c.x)-(this.x*c.y))/((c.x*c.x)+(c.y*c.y));
Fs m = new Fs(j,i);
return m;
}
*/
/* 第三版本
public Fs opp(Fs c,String op) {
if(op=="+") {
return new Fs(this.x+c.x,this.y+c.y);
}
if(op=="-") {
return new Fs(this.x-c.x,this.y-c.y);
}
}
*/
/* 第二版本
public Fs opp(Fs c,String op) {
if(op=="+") {
j=this.x+c.x;
i=this.y+c.y;
return new Fs(this.x+c.x,this.y+c.y);
}
if(op=="-") {
j=this.x-c.x;
i=this.y-c.y;
}
if(op=="*") {
j=(this.x*c.x)-(this.y*c.y);
i=(this.y*c.x)+(this.x*c.y);
}
if(op=="/") {
j=(this.x*c.x+this.y*c.y)/((c.x*c.x)+(c.y*c.y));
i=((this.y*c.x)-(this.x*c.y))/((c.x*c.x)+(c.y*c.y));
}
Fs m = new Fs(j,i);
return m;
}
*/
}
我实在是不知道错在哪了,或许是某个使用方法我不知道?求解