๐ WAYPOINT LESSON
Reading a specification
โญ beginnerโณ 12 min read๐ Lesson 69 of 256
Signatures, preconditions you may rely on, postconditions you must deliver.
An FRQ (free-response question) hands you a specification and asks for code that satisfies it. Reading the spec precisely is half the task. Every AP-style spec names:
- the method signature โ name, parameter types, return type. Match it exactly; the graders' tests call YOUR method with THEIR types.
- preconditions โ what's guaranteed true before the call ("the list has at least one element"). You may rely on these; never re-check them for points, never violate them.
- postconditions โ what must be true after the call ("returns the number of..."). This is the contract you must deliver.
// Precondition: wordCount >= 0
// Postcondition: returns the total number of characters across
// wordCount words, given their lengths
public static int totalChars(int[] lengths, int wordCount)
Write the postcondition as a comment in your own words BEFORE coding. If your restatement is wrong, every line after it is wrong too.