Design Recipe 2: for the body of a conditional function -

use with the Design Recipe 1.

 

Phase

Goal

Activity

Data Analysis

to determine distinct situations a function deals with

inspect the problem statement for distinct situation

enumerate all possible situations

Examples

to provide an example per situation

choose at least one example per situation

for intervals the examples must include borderline cases

Body (1) conditions

to formulate a conditional expression

        write down a skeleton of the cascaded if statement and its conditions with one clause per situation

        formulate one condition per situation, using the parameters

        ensure that the conditions distinguish the examples appropriately

Body (2)

answers

to formulate the answers to the conditional clauses

        deal with answer for each condition separately

        assume condition holds and develop Java expression that produces the appropriate answer for this case