OO Programming and Data Structures | CS 241

04 Prove : Assignment

Overview

This assignment will give you practice using classes in Python to model and e-commerce system with Customers, Orders, and Products.

Specification

For this program you will write separate classes for a Customer, Order, and Product. These classes should be in their own files and will therefore need to be combined into a .tar file to submit.

You will be provided with a main.py file that will test the properties and methods of your classes. This concept of having a file that tests each component in individually is called unit testing. It allows the developer of a library (you in this case) to feel confident that the classes that have been created are working correctly.

The main.py file is found at /home/cs241/assign04/main.py and can be copied to your directory as follows:


mkdir assign04
cd assign04

cp /home/cs241/assign04/main.py .

The main method will assume the classes exist as follows:

Product
id : string
name : string
price : float
quantity : int
__init__(id, name, price, quantity)
get_total_price()
display()
Order
id : string
products : Product[]
__init__()
get_subtotal()
get_tax()
get_total()
add_product(product)
display_receipt()
Customer
id : string
name : string
orders : Order[]
__init__()
get_order_count()
get_total()
add_order(order)
display_summary()
display_receipts()

Method Specification

The following describes the expected behavior of each of the above methods:

All dollar amounts should be displayed to two decimals.

Expected Output

The following demonstrates the expected output of the program:


### Testing Products ###
Id: 1238223
Name: Sword
Price: 1899.99
Quantity: 10
Sword (10) - $18999.90

Id: 838ab883
Name: Shield
Price: 989.75
Quantity: 6
Shield (6) - $5938.50

### Testing Orders ###
Order: 1138
Sword (10) - $18999.90
Shield (6) - $5938.50
Subtotal: $24938.40
Tax: $1621.00
Total: $26559.40

### Testing Customers ###
Summary for customer 'aa32':
Name: Gandalf
Orders: 1
Total: $26559.40

Detailed receipts for customer 'aa32':
Name: Gandalf

Order: 1138
Sword (10) - $18999.90
Shield (6) - $5938.50
Subtotal: $24938.40
Tax: $1621.00
Total: $26559.40

Summary for customer 'aa32':
Name: Gandalf
Orders: 2
Total: $1092198.36

Detailed receipts for customer 'aa32':
Name: Gandalf

Order: 1138
Sword (10) - $18999.90
Shield (6) - $5938.50
Subtotal: $24938.40
Tax: $1621.00
Total: $26559.40

Order: 1277182
The Ring (1) - $1000000.00
Wizard Staff (3) - $599.97
Subtotal: $1000599.97
Tax: $65039.00
Total: $1065638.97

Syntax Reminders and Hints

The following may come in handy in this assignment:

Automatic Grading Script (TestBed)

To assist you in your development, an automated test script is provided. Please keep in mind, that unlike checkpoints, your program will also be evaluated for code quality and correctness.

Because the main.py file is provided for you, it should match the testBed as soon as you fill in each of your classes and methods appropriately.


tar -cf assign04.tar *.py
testBed cs241/assign04 assign04.tar

Submission

Submit your program by logging into the CS Department Linux system, and running the submit command with your filename. Example:


submit assign04.tar

You should then select the appropriate course (CS 241), instructor, and assignment from the list.

Assessment and Grading

For your information, the instructor will use these assessment guidelines to evaluate your assignment. Feel free to refer to this to understand the expectations of this submission.