Page 370 - Introduction to Programming with Java: A Problem Solving Approach
P. 370
336 Chapter 8 Software Engineering
3. When adding a comment to a variable declaration, always begin the comment one space after the end of the declaration. (T / F)
4. To get the most on each line of code, always break a long line at the point determined by your text editor or IDE. (T / F)
5. For an if or while that has only one statement in its body, braces for the body are optional. The compiler does not require them, but proper style suggests that you should include them. Give at least one reason why it’s a good idea to put braces around the body’s single statement.
6. What’s wrong with the style of a class description that ends like this? }
}
}
What might you do to fix it?
7. What should you use to separate large “chunks” of code?
8. For each, write “yes” or “no” to indicate whether it is good style to include a blank space.
• afterthesingleasterisksintheprologue
• betweenamethodcallanditsopeningparentheses
• withineachofthethreecomponentsinaforloopheader
• afterthetwosemicolonsintheforloopheader
• between a closing brace and the //’s for its associated comment • after the //’s for all comments
• after the if, while, and switch keywords
§8.3 Helper Methods
9. Which of the following is a legitimate reason for creating a helper method?
Apago PDF Enhancer
a) You want the method to be hidden from the outside world.
b) You have a long and complicated method and would like to partition it into several smaller modules.
c) Your class contains two or more methods where some of the code is the same in both methods. d) All of above.
10. Does a class’s interface include the names of private methods?
§8.4 Encapsulation (with Instance Variables and Local Variables)
11. In the interest of encapsulation, use local variables instead of instance variables whenever possible. (T / F)
12. If a method modifies a particular instance variable, and if a program calls the same method two separate
times, the value of the instance variable at the beginning of the second method call is guaranteed to be the same as the value it had at the end of the first method call. (T / F)
§8.5 Design Philosophy
13. Since some of your preliminary code might change in the course of development, do not waste time testing
until everything is done. (T / F)
14. When you are testing a program, it’s important to not have any preconceived expectations of what your
output should look like. (T / F)
§8.6 Top-Down Design
15. The top-down design methodology is good because:
a) It keeps everyone focused on a common goal. (T / F) b) It avoids “reinventing the wheel.” (T / F)
c) It keeps management informed. (T / F)
d) It minimizes the chances of solving the wrong problem. (T / F)