AlgoMaster Logo
AlgoMasterDesign Beverage Stationeasy

Design Beverage Station

easy

A small café has one reliable routine for making a drink: boil the water, brew the drink, pour it, and add condiments when the recipe calls for them. Tea, coffee, and espresso all follow that routine, but each supplies its own brewing details.

The café already has a working BeverageStation. Your job is to implement only the classes that express the Template Method pattern:

  • BeverageMaker, the abstract base class that owns the preparation sequence.
  • TeaMaker, CoffeeMaker, and EspressoMaker, which provide the drink-specific steps.

Do not reimplement BeverageStation; it is included in the starter code and connects your classes to the tests. The tests use its public API:

  • BeverageStation() creates a station that has prepared nothing.
  • String[] prepare(String kind) prepares "tea", "coffee" or "espresso" and returns the steps it carried out, in order. Any other name returns ["UNKNOWN"] and prepares nothing.
  • boolean usesCondiments(String kind) returns whether that beverage takes the condiment step. An unrecognised name returns false.
  • int prepareCount() returns how many beverages have been prepared.
  • String lastPrepared() returns the name of the last beverage prepared, or "NONE" before any.

Every beverage runs these steps in this order: boil the water, brew, pour into the cup, and then add condiments if that beverage takes them.

  • Boiling always produces "Boiling water".
  • Pouring always produces "Pouring into cup".
  • Tea brews "Steeping the tea bag" and adds "Adding lemon".
  • Coffee brews "Dripping coffee through filter" and adds "Adding sugar and milk".
  • Espresso brews "Forcing water through the espresso puck" and takes no condiments, so its transcript ends after the pour.

Keep the preparation order in one template method on BeverageMaker. Concrete makers should fill in only what varies. Espresso should opt out of condiments through a hook, without duplicating the full recipe or making the base class check the beverage name.

Example 1:

Input:

Output:

Explanation: A fresh station prepares tea. The transcript lists the four steps in the order the skeleton fixed, the count moves to 1, and the station remembers what it made last.

Example 2:

Input:

Output:

Explanation: Coffee takes condiments, so its transcript ends with the sugar and milk step. Espresso answers the hook with false, so its transcript stops after the pour, and usesCondiments reports that before espresso is ever prepared.

Constraints

  • kind is a lower-case word of at most 20 letters.
  • At most 100 calls in total are made across all methods.

How the design is graded

needs 7/10 to pass
  • The skeleton lives in the base class

    Full marks when the four-step order is written once in a base-class method that subclasses cannot replace, and each beverage supplies only the steps that differ. Lose points heavily when the sequence is repeated inside each beverage class, or when the base class branches on the beverage name to decide what to run.

  • The hook is opt-out behaviour

    Full marks when one overridable method with a base-class default decides whether the condiment step runs, so espresso opts out by overriding that method alone. Lose points when the skeleton inspects which beverage it holds, or when espresso returns an empty condiment string that still occupies a slot in the transcript.

  • Structure and naming

    Full marks when boiling and pouring are private to the base class, an unrecognised name returns `["UNKNOWN"]` without counting or changing `lastPrepared`, and the station asks the beverage for its hook answer. Lose points for printing to stdout.

Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.

Hints

Loading...
CallReturns
new BeverageStation()null
prepare("tea")["Boiling water","Steeping the tea bag","Pouring into cup","Adding lemon"]
prepareCount()1
lastPrepared()"tea"

A fresh station prepares tea. The transcript lists the four steps in the order the skeleton fixed, the count moves to 1, and the station remembers what it made last.

Run checks these cases. Submit also runs a larger hidden set.