Menu
CoddyTech

Project: Model an Order

Lesson 43 of 48 in Coddy's Python for Java Developers course.

Build a four-stage order processor: a model, interchangeable pricing policies, validated batch input, and a summary. Transfer Java composition and integer-cents design to Python while using modules and callable methods. The same six files stay present throughout; each step states which behavior to replace. This project uses only in-memory data and standard input.

challenge icon

Challenge

Beginner

Begin a four-stage in-memory order processor. Implement Order(customer,quantity,unit_cents) and subtotal() in order.py. Inputs are a nonempty customer without a colon, positive integer quantity, and nonnegative integer cents, on three lines. Print customer:quantity:subtotal. Keep integer cents, as in a Java money model. Complete the subtotal while leaving the later policy/helper scaffolds in place. The starter runs with an unfinished result; all four steps keep the same files.

Editable files: order.py, standard_policy.py, bulk_policy.py, functions.py, main.py. Keep the provided imports and the required API names. The locked driver.py supplies execution and checks; do not edit it.

All four steps keep order.py, standard_policy.py, bulk_policy.py, functions.py, main.py, and locked driver.py. Keep the supplied entry wrapper. The driver calls main() once and then tests the APIs without more input or output. Each solution is the complete program through its step.

Try it yourself

from order import Order
from standard_policy import StandardPolicy
from bulk_policy import BulkPolicy
from functions import make_policy, parse_order
from main import main

main()

probe_order = Order("probe", 3, 7)
assert (probe_order.customer, probe_order.quantity, probe_order.unit_cents) == ("probe", 3, 7)
assert probe_order.subtotal() == 21
probe_order.quantity = 4
assert probe_order.subtotal() == 28
other_order = Order("other", 1, 0)
assert other_order.subtotal() == 0 and probe_order.subtotal() == 28

All lessons in Python for Java Developers

Practice on your own: Online Python compiler