Skip to main content

Section 9.7 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);
    
    _______ _______ trip (_______ one, _______ two, _______ three)
       A       B             C            D            E
    {
            /* 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();
    
    _______ _______ advance () { /* logic */ }
       A       B
    
    Blank A:
    Blank B:

    3.

    Q3: Fill in the blanks for a private method header that returns a String and accepts two integer parameters.
    _______ _______ calculate (_______ one, _______ two)
       A       B                  C            D
    {
       /* 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.
    _______ _______ nada () { /* logic */ }
       A       B
    
    Blank A:
    Blank B:

    5.

    Q5: Put the code in the right order to create a program that returns a double, and accepts as parameters 3 integers, and calculates the average of the inputs. There is also a main program that calls the method twice with different values.
You have attempted of activities on this page.