Skip to main content

Section 8.9 Assessment: Writing Methods

Subgoals for Writing Methods.

  1. Define method header based on problem
  2. Define return statement at the end
  3. Define method body/logic
    1. Determine types of logic (expression, selection, loop, etc.)
    2. Define internal variables
    3. Write statements

Exercises Exercises

    1.

    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:

    2.

    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:

    3.

    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:

    4.

    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.