|
Grab a Piece of Paper! |
Evaluate each expression.
Verify your answer by entering the code in the Java Playground.
|
Use the variable declarations to evaluate the boolean expressions that use the relational operators.
Learn more: Learn: Using Boolean Expression and Relational Operators
int a = 5, b = 3, c = 8, d = 2, e = 7;
double x = 6.5, y = 2.0, z = 3.5;
- (a + b) > c
- (d * b) <= e
- (x / y) == z
- (c - a) != d
- (a % d) < b
- (e + d) >= c
- (b - d) == (e % a)
- (x * y) < a
- ((a + c) / b) > d
- (e - a * d) <= b
You can use the Java Playground to check your answers.
Practice 1: Determine if highestScore needs to be updated
Write a code segment to set updateScore
to whether it should be updated based on the values of score
and highestScore
. The value of updateScore
is true
if score
is greater than highestScore
and false
otherwise.
- Determine example test values for
score
and highestScore
so that you are testing all three cases:
score
is greater than highestScore
score
is equal to highestScore
score
is less than highestScore
- Determine the expected value of
updateScore
for each of your three test cases.
- Complete the code segment below.
- Test your code segment with each test case. If it doesn't yield your expected outcome, make necessary changes to your code.
Practice 2: Determine if you can purchase an item based on the budget
Write a code segment to determine whether or not an item can be purchased. The value of canPurchase
is true
if price
is less than or equal to budget
and false
otherwise.
- Determine example test values for
price
and budget
so that you are testing all three cases.
- Determine the expected value of
canPurchase
for each of your three test cases.
- Complete the code segment below.
- Test your code segment with each test case. If it doesn't yield your expected outcome, make necessary changes to your code.
Practice 3: Determine if chicken is fully cooked
Write a code segment to determine whether or not an chicken is fully cooked. Chicken is fully cooked if its internal temperature greater than or equal to 165 degrees.
- Determine example test values for
temperature
so that you are testing all three cases.
- Determine the expected value of
safeToEat
for each of your three test cases.
- Complete the code segment below.
- Test your code segment with each test case. If it doesn't yield your expected outcome, make necessary changes to your code.
Practice 4: Determine if the class is full
Write a code segment to determine whether or not a class is full. The value of isClassFull
is true
if students
is equal to maxStudents
and false
otherwise.
- Determine example test values for
students
and maxStudents
so that you are testing all cases.
- Determine the expected value of
isClassFull
for each of your test cases.
- Complete the code segment below.
- Test your code segment with each test case. If it doesn't yield your expected outcome, make necessary changes to your code.
Practice 5: Determine if the id is ok to use
Write a code segment to determine whether or not an id is ok to be used. The value of isIdOK
is true
if id
does not equal invalidId
and false
otherwise.
- Determine example test values for
id
and invalidId
so that you are testing all three cases.
- Determine the expected value of
isIdOK
for each of your three test cases.
- Complete the code segment below.
- Test your code segment with each test case. If it doesn't yield your expected outcome, make necessary changes to your code.