Capstone · 10 min read · Beginner
Java Capstone: Order Summary Service
Combine records, List.of(), and Streams to build a clean, immutable Java order summary service.
What you'll learn
- Model OrderItem using a Java record with a derived subtotal() method
- Aggregate totals with mapToDouble().sum()
- Prepare for the Java Final Exam and Certificate
In this capstone, you will combine Java records, Streams, and clean encapsulation to compute an order total with zero mutable state.
Fill-in-the-Blank Capstone
Sum Record Subtotals with Streams
Map each OrderItem to its subtotal and sum them cleanly.
double total = items.stream()
.(OrderItem::subtotal)
.();Capstone Code Lab
JavaOrderService.java
Expected OutputClick “Run Live” to compile with OpenJDK 21
Items: 2 | Total: $120.00
Check Your Understanding
Score: 0 / 1
1. What does OrderItem::subtotal represent in items.stream().mapToDouble(OrderItem::subtotal)?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.