SR2. A function call is an expression, so it has a value. A procedure call is a
statement, so it does not have a value.
SR3. It must be a procedure call because it ends in a semicolon.
SR4 . The presence of keyword void tells you that it is a procedure.
SR5. A parameter is a variable that is declared within the parentheses of a
method definition (adjacent parameter declarations are separated by commas).
SR6. An argument is an expression that appears within the parentheses of a
method call (adjacent arguments are separated by commas).
SR7. To figure out what a call meth(a1, a2) does, copy the specification of the
method and replace all occurrences of the parameter names by the corresponding
SR8. The scope of a parameter —i.e. where it can be referenced— is the method
SR9. The scope of a local variable is the sequence of statements following its
declaration (until the end of the block in which the local variable is declared).
SR11 . return expression ;
Exercises for Chapter 2
Each exercise below asks you to write a method and test it thoroughly. To do this,
write a single class Functions and place all the functions and procedures in this
class. Here is how you can test a method. Suppose you named the function of the
first exercise average . Then, after writing the function and compiling class
Functions , type this expression into DrJava's Interactions Pane:
Functions.average(3, 5, 7)
Make sure you specify your methods, with comments that precede the method
definitions. If an exercise asks you to print values, label them suitably on the out-
put. For example, for the above function call, print average: 5.0 .
Write a function that returns the average of its three double arguments.
Write a procedure that prints the average of its three double arguments on