7.1. Worked Example: Writing Method HeadersΒΆ
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
You can watch this video or read through the content below it.
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)

public void maxTime (int a, int b, String c) {}
A call to this method would look like:
double x = obj.maxTime(5, 3, "happy");
Practice Pages