lundi 26 octobre 2015

Java If/Else Multiple Conditions

I am using an If/Else statement in Java with multiple conditions. Originally, I had 8 nested if statements, but combined them into one if with multiple && connectors. All conditions must be passed in order for the listed results to be shown. If any one condition is failed, the else statement must pass. I think I have structured my block correctly, but during testing the required results are not working properly. For example, I have changed ageCustInt so that it should fail and show "Not Compatible". This worked perfectly, then I changed ageCustInt back to an age that should pass, but I am still getting "Not Compatible". I have checked each of the other conditions and they all pass. Is my code incorrectly structured? I simply can not find why I am not getting correct results.

if (ageCustInt >= ageMinComp1Int && ageCustInt <= ageMaxComp1Int &&
            adtV1MileageCustInt >= adtVMileageMinComp1Int && adtV2MileageCustInt >= adtVMileageMinComp1Int && adtV3MileageCustInt >= adtVMileageMinComp1Int &&
            adtV1MileageCustInt <= adtVMileageMaxComp1Int && adtV2MileageCustInt <= adtVMileageMaxComp1Int && adtV3MileageCustInt <= adtVMileageMaxComp1Int &&
            totalViolationsCustInt >= totalViolationsMinComp1Int && totalViolationsCustInt <= totalViolationsMaxComp1Int &&
            totalAdtDriversCustInt >= adtDriversMinComp1Int && totalAdtDriversCustInt <= adtDriversMaxComp1Int &&
            bodilyInjuryCust.equals(bodilyInjuryComp1) &&
            propDamageCust.equals(propDamageComp1) &&
            unUiBodilyCust.equals(unUiBodilyComp1))
                    {
                    btnComp1.setVisible(true);
                    lblPriceComp1.setText("$ " + price1String);
                    lblPriceComp1.setVisible(true);
                    }               
        else
        {
            lblPriceComp1.setText("Not Competitive");
        }

Aucun commentaire:

Enregistrer un commentaire