Lab 7 Pre-Lab

The following exercises must be completed before you come to lab. Your instructor will check your pre-lab exercises at the beginning of the lab period. Completion of the pre-lab is worth 5 points of the total 30 points for the lab.

Given the following integer variables:

int i = 5;

int j = 7;

int k = 6;

int m = 2;

Evaluate the following Boolean expressions:

1. (i < j) && (k < m)

2. (i < j) || (k < m)

3. (m < k) || (j < m) && (i < j)

4. ((m < k) || (j < m)) && (i < j)

Given the following Boolean variables:

boolean a;
boolean b;
boolean c;
boolean d;

and the following code fragment (indenting purposely removed):

if (a && b)
{
if (!c && !d)
{
karel.setLabel("K");
}
else if (!d)
{
karel.setLabel("L");
}
else
{
karel.setLabel("M");
}
}
else if (c == d)
{
karel.setLabel("N");
}
else if (c)
{
karel.setLabel("O");
}
else
{
karel.setLabel("P");
}

Give values for a, b, c, and d that cause karel's label to become:

5. K

6. L

7. M

8. N

9. O

10. P

Remember to take your textbook to lab. You will need it.