Page 88 - Introduction to Programming with Java: A Problem Solving Approach
P. 88
54 Chapter 2 Algorithms and Design Review Question Solutions
1. The statement prints what is in quotation marks literally, and then prints the current value of the variable userName.
2. totalNumberOfStudents
3. Pseudocode that tells the computer to assign distance divided by time into a speed variable:
set speed to distance / time
4. Pseudocode statement:
input height
5. The three types of control flow discussed in Chapter 2 are sequential, conditional, and looping.
6. True. Looping is appropriate whenever the next thing done is something previously done.
7. After the code executes, the value of the variable, speedLimit, should be 65.
8. Yes. It’s OK because it’s only pseudocode, and it conveys the meaning unambiguously. However, if it were supposed to be code the computer could compile, the syntax would have to conform exactly to prescribed rules for a particular programming language like Java.
9. Flowchart that implements walk/drive logic:
print “Enter temperature in Celsius:”
Apago PDF Enhancer
input temperature print “Is it raining? (y/n): ” input raining
temperature
greater than 10 ? yes
raining?
no
no
yes
10. Provide a solution to the previous problem in the form of pseudocode.
print “Enter temperature in Celsius: ” input temperature
print “Is it raining? (y/n): ”
input raining
print “drive”
print “walk”