7.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

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.

Write a public method
public void maxTime (int a, int b, String c) {}

A call to this method would look like:

double x = obj.maxTime(5, 3, "happy");
You have attempted of activities on this page