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:
Product
init - Initializes to the values that were passed
get_total_price - Returns the price multiplied by the quantity
display - Displays the products name, quantity, and total price in the following format:
Pencil (10) - $12.90
Order
init - Initializes to id="", and products to an empty list []
get_subtotal - Sums the price of each product and returns it
get_tax - Returns 6.5% times the subtotal
get_total - Returns the subtotal plus the tax
add_product - Adds the provided product to the list
display_receipt - Displays a receipt in the format:
Order: 1138
Sword (10) - $18999.90
Shield (6) - $5938.50
Subtotal: $2889.74
Tax: $187.83
Total: $3077.57
Customer
init - Initializes to id="", name="", and orders to an empty list
get_order_count - Returns the number of orders
get_total - Returns the total price of all orders combined
add_order - Adds the provided order to the list of orders
display_summary - Displays a summary as follows:
Summary for customer 'aa32':
Name: Gandalf
Orders: 1
Total: $3077.57
display_receipts - Displays all the orders' receipts as follows:
Detailed receipts for customer 'aa32':
Name: Gandalf
Order: 1138
Sword (10) - $18999.90
Shield (6) - $5938.50
Subtotal: $2889.74
Tax: $187.83
Total: $3077.57
Order: 1277182
The Ring (1) - $1000000.00
Wizard Staff (3) - $599.97
Subtotal: $1000199.99
Tax: $65013.00
Total: $1065212.99
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:
Creating an empty list:
my_list = []Appending an item to a list:
my_list.append(item)Creating a tar file:
tar -cf assign04.tar *.py
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.