Programming Practice: Boolean Expressions and Predicate Methods


Boolean expression to truth table

Fill in the truth table for the following boolean expression:

!a || b && (a || !b)
ab!a || b && (a || !b)
TT 
TF 
FT 
FF 

Truth table to boolean expression

Given the following truth table:

abexpression
TTF
TFT
FTT
FFF

Using only boolean operators (&&  ||  !), write a boolean expression that has the truth table above.

 

 

If we lift the restriction of only using boolean operators, is there a simpler expression that has the truth table above?  If so, give it.

 

 


SimpleMug class

isEmpty method

Complete the (instance) isEmpty method below so that it determines if the mug is empty.

public boolean isEmpty() {



}

containsLiquid method

Complete the (instance) containsLiquid method below so that it determines if the mug contains the given liquid.

public boolean containsLiquid(String liquid) {



}

hasThirdLetter method

Complete the hasThirdLetter method below so that it determines if the given string has the given character as its third letter.

public static boolean hasThirdLetter(String str, char ch) {



}