199
15.You’ve written an application that displays the corresponding digit on a phone,
given a letter of the alphabet. Everything seems to work right except that you
can’t get the digit 5 to display; you keep getting the digit 6. What steps would you
take to find and fix this bug? (pp. 190–195)
Answers
1.false,true,false2.It enables us to choose one course of action (control flow path) or another.3.Four paths.
4.The iflets us choose whether to perform an action; the if-elseallows us to choose between two courses of
action.5.a. N, b. S, c. S, d. S, e. N 6.A nested ifstructure 7.To have a team verify the algorithm through hand-
simulation 8.The implementation phase 9.By making the class self-contained and independent of the code
that uses it 10.letter < 'Z’11.letter >= 'A’&& letter <= 'Z’12.if(value > 0 ) value = -value;13.if(value >
0 ) value = -value; elsevalue = 1 ;14.A nested ifstatement 15.Carefully review the section of code that should
display 5. Check the branching condition and the output statement there. Try some sample values by hand.
Exam Preparation Exercises
1.What is the purpose of a control structure?
2.What is a logical expression?
3.Given the following relational expressions, state in English what they say.
Expression Meaning in English
one == two
one != two
one > two
one < two
one >= two
one <= two
4.Given these values for the booleanvariables x,y, and z:
x = true
y = false
z = true
evaluate the following logical expressions. In the blank next to each expression,
write a T if the result is trueor an F if the result is false.
_____ a. x && y || x && z
_____ b. (x || !y) && (!x || z)
_____ c. x || y && z
_____ d. !(x || y) && z