-kric- 2019-05-18 10:11 采纳率: 0%
浏览 326
已采纳

MVC开发模式,javabean中函数if分支语句好像不起作用?换成switch-case就正确了,为什么?

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;
    }
*/      

}

我实在是不知道错在哪了,或许是某个使用方法我不知道?求解

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-05-18 10:25
    关注

    Java的字符串比较用的是equals不是==

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。