Skip to main content

Exam FRQ: the recipe scaler

Challenge on lesson: Checkpoint: exam #2 FRQ

CHALLENGE
Difficulty: advanced+25 XP

45-minute FRQ section. Implement the Recipe class: - constructor takes the base servings (int) and base sugar (int grams) - scaleTo(int servings) returns the sugar needed for the requested servings: baseSugar * servings / baseServings (integer division) - addServings(int extra) increases the REMAINING planned servings (starts equal to baseServings; never below 0) - remaining() reports planned servings - serve(int n) reduces remaining by n, floored at 0, and returns true if there were enough servings planned, else false (changing nothing when false) Implement the class.

Back to lesson: Checkpoint: exam #2 FRQ