Design Recipe 1: Designing simple computational functions (methods).






and Header

to name the function;

to specify its classes of input data


and its classes of output data;





to describe its purpose;

to formulate a header

choose a name that fits the problem

        study the problem for clues on how many unknown "givens" the function consumes

        identify the type of data for each of the "givens"

        describe what the method should produce using the chosen variables

        determine the type of data the function (method) should produce

        formulate the purpose and signature (header):

/* to compute ... given par1, par2 ... */

result-type name(par-type1 par1,

par-type2 par2, ...){




to characterize

the input-output relationship via examples

Design examples of invoking this function (method)


to define the function

        formulate how the function computes its result

        develop a Java expression that uses Java's primitive operations, other functions, and the variables

        translate the mathematical expressions in the problem statement, when available


to discover mistakes

("typos" and logic)

        apply the function to the inputs of the examples

        check that the outputs are as predicted