Boolean logic 逻辑或条件未按预期工作

Boolean logic 逻辑或条件未按预期工作,boolean-logic,Boolean Logic,在我的Decision类中,我有3个条件语句,如下所示: GeneralCondition类包含promptUser(用户) //下面是CAALING interruptUser()类: 类UserCondition扩展了GeneralCondition{ GeneralCondition gcon=新的GeneralCondition() if(gcon中断用户(用户)){ //重定向到条件弹出流 } 否则 { //重定向到主页 } } 中断用户(user)被其他对象调用。当我使用上述所有3个

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

GeneralCondition类包含promptUser(用户)

//下面是CAALING interruptUser()类:

类UserCondition扩展了GeneralCondition{

GeneralCondition gcon=新的GeneralCondition()

if(gcon中断用户(用户)){

//重定向到条件弹出流

}

否则

{

//重定向到主页

}

}


中断用户(user)
被其他对象调用。当我使用上述所有3个条件时,每次它返回False,即使它是true;当我只使用2个条件时,它会按预期工作。请说明可能的原因。

似乎您正试图用Java编程语言测试此程序。问题是您的代码不正确,很可能永远不会编译。

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

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

@DavidSchwartz:它在Java1.5中,你的驱动程序类在哪里?用户类定义如何?您需要粘贴所有源文件,包括驱动程序,以找出错误所在。这与您编写的方法相同。我只是在发帖时错过了。但当我使用这三种方法时,结果总是错误的。当尝试使用2条件时,它工作正常。听起来好像你输入了代码,而不是复制和粘贴它。请复制并粘贴准确的代码,否则我们会浪费时间弄清楚你把事情搞砸了:)
boolean interruptUser(User user){
    boolean hasChildrens = hasChildrens(user);
    boolean hasSpouse = hasSpouse(user);
    boolean newUser = newUser(user);
    return hasChildrens || hasSpouse || newUser;
}