Section 4. Chapter 4
single
Challenge: Processing a Coffee Order
Swipe to show menu
Task
Swipe to start coding
You'll simulate how a coffee shop processes an order from start to finish — from the moment it is placed, to how it is displayed on a final receipt.
You'll work with string immutability, manipulation, and formatting to build a realistic order flow.
- Create 3 variables with the following exact values:
drinkName("Latte")quantity(2)price(3.5f)
- Simulate a change in the order by updating the drink name from
"Latte"→"Cappuccino"(this represents how the original string is replaced, not modified). - Convert the updated drink name to uppercase using
toUpperCase(), as receipts display product names in a standardized format. - Create a formatted receipt message using
String.format()that includes:- product name
- quantity
- price per item (1 decimal place)
- Check whether the final receipt message is empty using
isEmpty()and store the result in abooleanvariable. - Print all results. Output should be as follows:
Original order: Latte
Updated order: Cappuccino
Formatted receipt: Product: Cappuccino | Quantity: 2 | Price: 3.5
UPPERCASE PRODUCT: CAPPUCCINO
Receipt is empty: false
Solution
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 4
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat