Free Shipping

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

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 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.

QUESTION 16:

Rewrite this 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 =