1

My code look like this(sample)

if(age>65 && gender.equals("M")&&country.equals("USA")&& salary>4000){
    //some logic
}else{
    //some logic
}

Some if condition is even longer than this. I want to create a method that will take all conditions evaluate the value and return true or false.

I want something like:

if(AND(age>65 , gender.equals("M"),country.equals("USA"), salary>4000)){
    //some logic
}else{
    //some logic
}
soufrk
  • 825
  • 1
  • 10
  • 24
  • How? You write code... That's your job. We just (maybe) try help fix what you've written. – Marc B Apr 28 '16 at 15:47
  • Do you want to replace the hard-coded business-logic with a more generic approach (i.e. reading the business rules from an external file) and evaluate it and act according to the result? Maybe you want a rule-engine like drools or something similar. If you want a basic draft of what should be done have a look at [this thread](http://stackoverflow.com/questions/20763189/creating-a-simple-rule-engine-in-java/20892587) – Roman Vottner Apr 28 '16 at 15:57

1 Answers1

-2

try this:

public static boolean AND(Boolean...args){
        boolean result=true;
        for(boolean value:args){
            if(!value){
                result= false;
                return result;
            }
        }
        return result;
    }
saumik gupta
  • 167
  • 2
  • 10