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.

18. More De Morgan

Answer:

Using the De Morgan Rule

    !(A && B) is equivalent to !A || !B

The expression

    boolean discount = !( (days < 14) && onSeason );

is equivalent to

    boolean discount = !(days < 14) || !onSeason ;

which can be further transformed to

    boolean discount = days >= 14 || !onSeason ;

More De Morgan

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.


Question 18:

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;

Assume that passenger refers to an object with an integer member age  and a boolean member licensed.

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.