Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Processing a Coffee Order | Strings
Introduction to Java
Section 4. Chapter 4
single

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.

  1. Create 3 variables with the following exact values:
    • drinkName ("Latte")
    • quantity (2)
    • price (3.5f)
  2. Simulate a change in the order by updating the drink name from "Latte""Cappuccino" (this represents how the original string is replaced, not modified).
  3. Convert the updated drink name to uppercase using toUpperCase(), as receipts display product names in a standardized format.
  4. Create a formatted receipt message using String.format() that includes:
    • product name
    • quantity
    • price per item (1 decimal place)
  5. Check whether the final receipt message is empty using isEmpty() and store the result in a boolean variable.
  6. 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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt