Comparing Boolean Expressions FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

Complete the table for !(p || q) and !p && !q. Then state whether the two expressions are equivalent.

p q !(p || q) !p && !q
false false
false true
true false
true true

Question 2 of 5

A road sensor uses !(speed > 50 && wet).

(a) Rewrite the expression using De Morgan's law, with ! applied to each original operand. (b) Evaluate the original when speed is 60 and wet is true. (c) Evaluate your rewrite with the same values.

Question 3 of 5

Show that ! (a && !b) is equivalent to !a || b.

(a) Complete a four-row truth table with columns a, b, !(a && !b), and !a || b. (b) State whether the last two columns match in every row. (c) Briefly connect the table to De Morgan's law.

Question 4 of 5

Three String variables refer to bay labels.

String u = new String("bay");
String v = new String("bay");
String w = u;

(a) State the value of u == v. (b) State the value of u.equals(v). (c) State the value of u == w and explain the difference between == and equals for these objects.

Question 5 of 5

A Pass stores a color code. Pass.equals returns true when both objects are non-null Pass objects whose codes are equal according to String.equals.

Pass p = new Pass("RED");
Pass q = new Pass("RED");
Pass r = p;
Pass z = null;

(a) Compare p == q with p.equals(q). (b) Compare p == r with p.equals(r). (c) Write a boolean expression that is true only when z is a non-null Pass whose code is RED, and that does not throw when z is null. (d) Explain why z.equals(p) is unsafe.