Mug
Own value: $12.00. No children to visit.
Appearance
COMPOSITE / PRACTICE
Transfer the file-tree idea to a gift shop. Price individual products and nested boxes through one contract, then add a new kind of leaf.
YOUR MISSION / GIFT SHOP
Checkout must price one product or a box containing products and more boxes. Only contents contribute to the total: an empty box is $0, and there is no packaging fee. Build the design, test all three cases, then add a gift card.
File → Product · Folder → GiftBox · size() → price(). Groups still ask each child for the same operation. Prices are fictional integer-cent values in a local simulation.
01 / BUILD THE DESIGN
Choose how checkout calls an item, how a box combines its children, and where its total starts.
Try your own design first. Hints and retries are unlimited.
02 / TEST · TRACE · VERIFY
Verify all three cases with the same design. We check both the total and the common-contract boundary. A correct number alone can hide type-dependent code.
Own value: $12.00. No children to visit.
Finish the trace to verify this case. Expected: $12.00.
03 / THE FINAL CHALLENGE
A gift card is a new leaf worth $25. It implements Priced directly; it does not inherit from Product. Which edits let it work inside the existing box?
Choose the two required edits, then press Apply edits & trace. Follow the gift card’s price back through its box to complete Practice.
Verify all three base cases with one design to unlock this extension.
0 of 2 edits selected
Hints and retries are unlimited. Revealing the answer does not verify any cases.