Order Model
Your task
Build an order model. Items are added only through addItem, and the total must always equal the sum of the items (unit price × quantity). Complete Order.
Ground rules
- •Single-threaded operation is assumed.
- •Items are added only through addItem.
Not required
- •Order cancellation and item removal.
- •Payment and discount calculation.
▶About this challenge
Complete a plain-Java (no framework) Order model. Items are added only through a designated method, and the total must always equal the sum of the items (unit price × quantity). You practice verifying that an object keeps its own rule (total = sum of items).
An object should be able to keep the rules it is responsible for (for example, total = sum of items) on its own. This problem completes an Order model that keeps the total equal to the sum of items as items are added through its designated method, and verifies in real code that the total always equals the sum of items.
- What ability does this problem practice?
- Making an object keep its own rule (total = sum of items), and verifying that the total always equals that sum as items are added.
- What should I confirm?
- After adding items through the designated method, confirm the item count and the total equal the sum of the items added.
- How do I run this problem?
- The sandbox has no network access and dependencies are pre-fetched into the image. Run the tests with gradle test --offline --console=plain.