Skip to main content

Section 8.1 Worked Example: Writing Method Headers

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

Subsection 8.1.1

You can watch this video or read through the content below it.

Subsection 8.1.2

Problem: Write a public method header that accepts as parameters 2 integers and a String in this order and calculates the maximum time of something and returns a double value.
For this Worked Exmaple, we will focus on SG1: Define method header based on problem.
  • When you pick your method name:
    • Make it something related to the use of the method.
    • Recall that method names are never capitalized at the first letter.
    • We will call this method maxTime
  • A full method header contains:
    • access modifier,
    • return type,
    • method name, and
    • full parameter list (data type parameter_name)
Figure 8.1.1.
public void maxTime (int a, int b, String c) {}
A call to this method would look like:
double x = obj.maxTime(5, 3, "happy");

Subsection 8.1.3 Practice Pages

You have attempted of activities on this page.