Truth Tables and De Morgan's Rules
Read this chapter, which discusses Boolean variables as used in decision tables. Truth tables are used to collect variables and their values relative to decisions that have to be made within control structures.
16. Free Shipping
Answer:
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 );
Free Shipping
For an on-line shopping site, shipping is free for purchases of $50 or more, unless the merchandise is 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.
Question 16:
Rewrite the second expression in two steps. In the first step, apply De Morgan's rule that
!(A && B)
is equivalent to!(A) || !(B)
.boolean shipping =
In the second step, rewrite the relational expression:
boolean shipping =