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.

17. Full Price Hotel


Using the De Morgan Rule

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

the expression

        boolean shipping =  !(purchase >= 50 && !onSale );

is equivalent to

        boolean shipping =  !(purchase >= 50) || !!onSale ;

which can be further transformed to

    boolean shipping = purchase < 50 || onSale ;

Full Price Hotel

A hotel charges full price for its rooms during the "on season" when a reservation is made less than 14 days in advance. Otherwise, a reservation qualifies for a discount.

boolean fullFare = (days < 14) && onSeason;

Assume that onSeason is a boolean variable. Here is an expression that says when a discount rate may be available:

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

Question 17:

Rewrite this expression in two steps. In the first step, apply De Morgan's rule that !(A && B) is equivalent to !A || !B.

    boolean discount =
In the second step, rewrite the relational expression:
    boolean discount =