← All Exercises
Partition Paid and Unpaid Orders
basicjava
Background
Partitioning is a two-bucket grouping with a boolean key. It always returns both buckets, which simplifies reports that must show zeros explicitly.
Problem
Given orders with an amount and a paid flag, partition them by payment status, report count and total per partition, and identify the largest unpaid order.
Input
A list of Order records with a unique id, a non-negative amount, and a paid boolean; the list may be empty.
Output
Printed lines paid=<n> total=<sum>, unpaid=<n> total=<sum>, and largest_unpaid=<id> <amount> only when an unpaid order exists.
Sample tests
Sample 1
Input: A-1 120.00 paid; A-2 80.50 unpaid; A-3 200.00 paid; A-4 45.25 unpaid
Expected: paid=2 total=320.00 unpaid=2 total=125.75 largest_unpaid=A-2 80.50
Sample 2
Input: one paid order B-1 10.00 and no unpaid orders
Expected: paid=1 total=10.00 unpaid=0 total=0.00 no largest_unpaid line
Your solution
Learning objective
Use partitioningBy with and without a downstream collector, then combine an Optional max safely.