逻辑或条件未按预期工作

发布于 2024-12-05 18:59:08 字数 1072 浏览 0 评论 0原文

在我的 Decision 类中,我有 3 个条件语句,如下所示:

GeneralCondition 类包含提示用户(用户)。

class Decision extends GeneralCondition{
    private boolean hasChildrens(User user){
        return user.getHaveChilds();
    }

    private boolean hasSpouse(User user){
        return user.getHaveSpouse();
    }

    private boolean newUser(User user){
        return user.isNewUser();
    }

    boolean interruptUser(User user){
        boolean hasChildrens=boolean hasChildrens(User user);
        boolean hasSpouse= boolean hasSpouse(User user);
        boolean newUser= newUser(User user);
        return hasChildrens||hasSpouse||newUser;
    }
}

//下面是调用interruptUser()的类:

class UserCondition extends GeneralCondition{

GeneralCondition gcon=new GeneralCondition();

if(gcon.interruptUser(user)){

//重定向到条件 PopUp Flow;

}

else

{

//重定向到主页;

}

}

interruptUser(user) 被其他对象调用。当我每次都返回 False 时使用上述所有 3 个条件,即使它是 true ;当我只使用 2 个条件时,它会按预期工作。请提出可能是什么原因。

In my Decision class, I have 3 conditional statement like below:

GeneralCondition class contains promptUser(user).

class Decision extends GeneralCondition{
    private boolean hasChildrens(User user){
        return user.getHaveChilds();
    }

    private boolean hasSpouse(User user){
        return user.getHaveSpouse();
    }

    private boolean newUser(User user){
        return user.isNewUser();
    }

    boolean interruptUser(User user){
        boolean hasChildrens=boolean hasChildrens(User user);
        boolean hasSpouse= boolean hasSpouse(User user);
        boolean newUser= newUser(User user);
        return hasChildrens||hasSpouse||newUser;
    }
}

//Below is the class caalling interruptUser():

class UserCondition extends GeneralCondition{

GeneralCondition gcon=new GeneralCondition();

if(gcon.interruptUser(user)){

//redirect to condition PopUp Flow;

}

else

{

//redirect to Home Page;

}

}

interruptUser(user) is called by other object. When I use all 3 condition as above every time it returns False, even if it is true; and when I use only 2 condition it works as expected. Please suggest what could be reason.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2024-12-12 18:59:08

看起来您正在尝试使用 Java 编程语言测试该程序。问题是您的代码不正确,并且很可能永远无法编译。

Seems like you are trying to test this program with the Java programming language. The problem is that your code is not correct and will never compile, most likely.

落花随流水 2024-12-12 18:59:08

试试这个。该函数需要传入一个 User 对象,然后将该对象传递给每个需要它的测试函数。

boolean interruptUser(User user){
    boolean hasChildrens = hasChildrens(user);
    boolean hasSpouse = hasSpouse(user);
    boolean newUser = newUser(user);
    return hasChildrens || hasSpouse || newUser;
}

Try this. The function needs to have a User object passed in, and then pass that object to each of the test functions that needs it.

boolean interruptUser(User user){
    boolean hasChildrens = hasChildrens(user);
    boolean hasSpouse = hasSpouse(user);
    boolean newUser = newUser(user);
    return hasChildrens || hasSpouse || newUser;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文