7.4. Assessment: Writing MethodsΒΆ
Subgoals for Writing Methods
Define method header based on problem
Define return statement at the end
Define method body/logic
Determine types of logic (expression, selection, loop, etc)
Define internal variables
Write statements
Q1: Fill in the blanks for a public method header that would work for this call:
int fob;
fob = obj.trip(4.1, "alphabet", 8);
___A___ ___B___ trip (___C___ one, ___D___ two, ___E___ three)
{
/* logic */
}
Blank A:
Blank B:
Blank C:
Blank D:
Blank E:
Q2: Fill in the blanks for a public method header that would work for this call:
obj.advance();
___A___ ___B___ advance () { /* logic */ }
Blank A:
Blank B:
Q3: Fill in the blanks for a private method header that returns a String and accepts two integer parameters.
___A___ ___B___ calculate (___C___ one, ___D___ two)
{
/* logic */
}
Blank A:
Blank B:
Blank C:
Blank D:
Q4: Fill in the blanks for a private method header that returns nothing and takes no parameters.
___A___ ___B___ nada () { /* logic */ }
Blank A:
Blank B:
You have attempted of activities on this page