Using the De Morgan Rule
!(A || B)
is equivalent to!A && !B
The expression
boolean oilOK = !( months >= 3 || miles >= 3000 );
is equivalent to
boolean oilOK = !( months >= 3 ) && !( miles >= 3000 );
which can be further transformed to
boolean oilOK = ( months < 3 ) && ( miles < 3000 );
For an on-line shopping site, shipping is free for purchases of $50 or more, unless the merchandise was on sale.
boolean freeShipping = purchase >= 50 && !onSale;
Here is an expression that shows when to charge for shipping:
boolean shipping = !( purchase >= 50 && !onSale );
Assume that onSale
is a boolean variable.
Rewrite this expression in two steps.
In the first step, apply De Morgan's rule that !(A&&B)
!(A)||!(B)
boolean shipping =
In the second step, rewrite the relational expression:
boolean shipping =