CS141: Topics for Sept 30 and Oct 2 & 4, 2013
Please look at Study Page. We will review on Wednesday.
Homework and Reading
The reading and homework for this week can be found here: Lab 6: Methods
Chp 5 Vocabulary (continued from last week)
For practice, check out the WileyPlus Chapter 5 Flash Cards!
method (function, member function, procedure)
stepwise refinement (revisited)
return type, return value
(formal) parameter variable
argument (actual parameter)
variable scope: local, global
Common expressions are:
"call a method" or "call a function"
"return a value"
"pass a value as a parameter"
Topics: Chp 5 - Methods (continued from last week)
- What are methods and why do we want them? E.g. Math.round, rolling a die.
- Why use methods?
- modularity and testing
- structure and readability
- Look at the structure of Part 1 of the BlackJack game.
- Components of a Method Declaration
- header (first line, aka the method signature) - contains the return type, method name, parameter list
- method body
- If the return type is not void, the method body must contain a return statement
- declare or write a method
- call a method
- arguments (actual parameters) vs formal parameters
- passing in a parameter (argument)
- Tracing the code - stepping through the code line-by-line. Do you understand the order the statements are executed?
- Scope - see problem in previous Exam 2
- Writing code using stepwise refinement - methods make this easy to do.
- Recursive methods - looping without loops or solving the towers of hanoi
In Class Practice Activities