The spec table contract
Translating rows exactly; why field order inside methods is specification.
The Q2 spec table is a fill-in-the-blanks contract. A representative table โ this module's checkpoint โ reads:
Class: Signaler
Fields:
- private int level (current signal level, starts at 1)
- private int streak (consecutive strengthens, starts at 0)
Constructor: Signaler() โ both fields at start values.
Methods:
void boost() โ level += streak; then streak++
void reset() โ level back to 1; streak back to 0
int getLevel() โ reader
The workflow is mechanical: translate each row, in order. Two rows deserve special respect:
"starts at 0/1" โ set it in the CONSTRUCTOR, not lazily. Graders check the initial state with a getter call before any mutation.
Order inside a method matters. boost() adds the CURRENT streak
to level, THEN increments streak. Swapping the two lines changes every
subsequent value โ trace boost; boost; boost: levels 1+0=1, 1+1=2,
2+2=4 vs (if swapped) 1+1=2, 2+2=4, 4+3=7. Both are "implementations";
only one matches the table. When the table gives an order, the order
is the specification.