user3772305
user3772305

Reputation: 39

Java If Statement with && and .equal

I have the following:

Team A:
#   Name
0-1 Tim
2-3 Ryan
3-4 Jim

Team B:
#   Name
0-1 John
2-3 Joan
3-4 Todd

I would like to write an if statement when I only have the # value and the team. So if I knew someone had a value of 1 and was on Team A, I would want it to show "Tim." This is what I have come up with so far but I am not having any luck. Any suggestions?

if(#>=0 & Team.equal("Team A")) {
  'Tim'
 } else if(#<=1 & Team.equal("Team A")) {
   'Tim'
 } else if(#>=2 & Team.equal("Team A")) {
   'Ryan'
 } else if(#<=3 & Team.equal("Team A")) {
   'Ryan'
 } // etc.. until all the people are listed in the conditions. 

Upvotes: 1

Views: 186

Answers (2)

Jakub Kubrynski
Jakub Kubrynski

Reputation: 14149

Please take a look at SmartParam project. It allows you to define all conditions in plain file and evaluate using its engine. You can find similar solution in this tutorial

Upvotes: 1

Adam Yost
Adam Yost

Reputation: 3625

Do blocked checks. Check team, then >0, then specifics.

if(team.equals("Team A"){
    if(num>=0){
        if(num <2)
           return "Tim";
        else if(num<4)
           return "Ryan";
         ...etc
    }
}
else if(team.equals("Team B"){
   ... etc
}

Upvotes: 1

Related Questions