StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 1 · Beans & Dependency Injection

Coffee Shop Order Printer

easyConstructor InjectionBean Validation44%36 of 81 solved

Problem statement

Connect the parts of a coffee shop ordering API using constructor injection.

Requirements

The receipt logic, request validation, the Menu and error handling are already provided. Your task is to connect the classes using constructor injection.

OrderService

  • Inject Menu through the constructor
  • The provided receipt logic uses the injected Menu to look up items and prices

OrderController

  • Inject OrderService through the constructor
  • Once it is injected, POST /orders returns the receipt
Sample Requests & Responses

POST /orders

Request:

{
  "items": [
    { "name": "Espresso", "quantity": 2 },
    { "name": "Latte", "quantity": 1 }
  ]
}

Response (200 OK):

Espresso x2 $5.00
Latte x1 $3.75
TOTAL $8.75

POST /orders

Request:

{
  "items": [
    { "name": "Americano", "quantity": 1 }
  ]
}

Response (200 OK):

Americano x1 $3.00
TOTAL $3.00

POST /orders

Request:

{
  "items": [
    { "name": "Flat White", "quantity": 1 }
  ]
}

Response (400 Bad Request):

{
  "error": "Unknown menu item: Flat White",
  "timestamp": "2026-07-20T11:27:49.607337",
  "path": "/orders"
}

POST /orders

Request:

{
  "items": [
    { "name": "Espresso", "quantity": 0 }
  ]
}

Response (400 Bad Request):

{
  "error": "Quantity must be at least 1",
  "timestamp": "2026-07-20T11:27:49.628058",
  "path": "/orders"
}

More in Beans & Dependency Injection

See the module
Temperature Unit Provider SwitcherThis problem covers registering two temperature converters and telling Spring which one to use by default and which one to hand over when it is asked for by name.59%10 of 17 solvedeasyFeature Flag Bean RegistryThis problem covers creating a set of feature on/off switches as Spring beans, filling each one from the settings file, and passing them all to the class that reports them.80%4 of 5 solvedeasyNotification Dispatch SelectorThis problem covers sending a message through the channel the user picked, and what to fall back to when the channel isn't recognized.75%3 of 4 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.