Using the De Morgan Rule
!(A && B)is equivalent to
!A || !B
boolean discount = !( (days < 14) && onSeason );
is equivalent to
boolean discount = !(days < 14) || !onSeason ;
which can be further transformed to
boolean discount = days >= 14 || !onSeason ;
De Morgan's rules can be extended to three operands:
!(A && B && C)is equivalent to
!A || !B || !C
!(A || B || C)is equivalent to
!A && !B && !C
Expressions with more than three operands behave similarly.
A driver holding a learner's permit may drive a car only during daylight hours and only if accompanied by a licensed driver of age 21 or over.
boolean drivingOK = daylight && passenger.age >= 21 && passenger.licensed;
passenger refers to an object with an integer member
and a boolean member
Here is an expression that says when driving is not permitted:
boolean noDriving = !(daylight && passenger.age >= 21 && passenger.licensed );
Transform this into a simpler expression.