Writing Methods
Worksheet
Matching: Identify the code segments indicated in bold as:
a) Method header
b) Method call
c) Arguments (actual parameters)
d) Formal parameters
e) Object name
f) Method name
g) Error
1.[Link](2, 8);
2.[Link]("Hello",5);
3. public void welcome(String back)
4. [Link]("Hello",5);
5. public void doStuff(String num)
6. [Link](27.5);
7.Helper help = new Helper();
int n1 = 12;
int n2 = 5;
[Link](int n1, int n2);
8.Fill in the method header below with two formal parameters called n1 and n2. The data passed in will
be used as whole numbers.
public void addNums( , )
9.Fill in the method header with two parameters that will be used for a person’s name and a dollar amount
(in that order). You may create your own variable names.
public void mystery( , )
10. Fill in the method header that corresponds to the following method call. There are 7 blanks, you may
have to scroll to see them all. You can create the variable names.
[Link]("Bob", 45, 12.99);
Writing Methods
Worksheet
public void ( , , )
11. Consider the following method header in a class called Farm:
public void chicken(String name, double weight)
The chicken's name is "Charlie" and weighs 6.7 pounds. Below is the program segment in the main
method. Write the method call to activate the chicken method.
Farm animal = new Farm();
. ( , );