Reputation: 22526
Java 8
I have the following chart that will do something based on the conditions in the below table
Just wondering is this the best way to satisfy all conditions
private void setDisplayTheStars() {
if (discount && rate) {
2Stars = true;
}
else if (!discount && rate) {
2Stars = true;
}
else if (discount && !rate) {
1Stars = true;
}
}
Upvotes: 1
Views: 39
Reputation: 17900
You should set 2Stars
if rate
is true;
Then check if discount
is true - then set 1Stars
to true.
if (rate) {
2Stars = true;
}
else if (discount) {
1Stars = true;
}
If you are declaring boolean, then it can be done as
boolean twoStars = rate == true;
boolean oneStars = !twoStars && discount == true;
Upvotes: 4