Oil Change

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 original expression

while ( !(input.equals( "quit" ) || (count > limit)) ) 
{
   . . . 
}

is equivalent to

while ( !input.equals( "quit" ) && !(count > limit)) ) 
{
   . . . 
}

which is equivalent to

while ( !input.equals( "quit" ) && (count <= limit)) ) 
{
   . . . 
}

Oil Change

The owner's manual for a car says to change the oil every three months or every 3000 miles.

boolean newOilNeeded =  months >= 3 || miles >= 3000 ; 

Here is an expression that shows when no oil change is necessary:

boolean oilOK =  !( months >= 3 || miles >= 3000 ); 

QUESTION 15:

Rewrite the expression using one of De Morgan's rules. Do this in two steps. In the first step, don't change the relational expressions.

boolean oilOK =   

Now further simplify by changing the relational expressions.

boolean oilOK =