Programming Assignment 5 (Orders Database)
In this programming assignment, you will develop a Python program to keep track of data that is typically kept in a consumer sales company. In particular, we will keep track of customers, parts, and orders placed by customers.
We will use six Python Classes:
- Customer.py: encapsulates information such as cno, cname, and city
for the customer object. The constructor method is shown below:
def __init__(self,cnum,name,cty): self.cno = cnum self.cname = name self.city = cty
- Customers.py: encapsulates information about ALL customers in a dictionary
format. The customer number will serve as the "key" in the dictionary and
the Customer object containing details of the customer will serve as the value for the key.
The constructor method is shown below:
def __init__(self): self.customers = {}
- Part.py: encapsulates information such as pno, pname, and price
for the part object. The constructor method is shown below:
def __init__(self,pnum,name,price): self.pno = pnum self.pname = name self.price = price
- Parts.py: encapsulates information about ALL parts in a dictionary
format. The part number will serve as the "key" in the dictionary and
the Part object containing details of the part will serve as the value for the key.
The constructor method is shown below:
def __init__(self): self.parts = {}
- Order.py: encapsulates information such as ono, placed_by, order_date, and a list of
triples: (part, quantity, discount) for parts that are included in the order.
The constructor method is shown below:
def __init__(self,ono,cust,d): self.ono = ono self.placed_by = cust self.order_date = d self.items = [] # will contain triples (part,quantity,discount)
- Orders.py: encapsulates information about ALL orders in a dictionary
format. The order number will serve as the "key" in the dictionary and
the Order object containing details of the order will serve as the value for the key.
The constructor method is shown below:
def __init__(self): self.orders = {}
The program takes the name of a folder as command line argument. This folder should contain three data files:
data/customers.dat
data/parts.dat
data/orders.dat
The customers.dat file contains customer number, customer name, and city (one customer per line) with the ":" symbol separating the values.
The parts.dat file contains part number, part name, and the unit price (one part per line) with the ":" symbol separating the values.
The orders.dat file contains data about each order, one order per line. The line begins with a unique order number, followed by customer number who placed the order, followed by date of order, followed by a sequence of 3 integers denoting part number, quantity, and discount. The three integers are separated by commas and the various components in the line are separated by ":", including the sequence of three integers. For example, the following line:
ATL-1000:1111:12-10-2022:1000,5,20:1001,20,10:1004,15,15indicates order with ono="ATL-1000" placed by customer with cno=1111 on "12-10-2022". The parts that are included in the order are: (1000,5,20), (1001,20,10), and (1004,15,15). When you store this data in the Order object, you will have to locate the Customer object corresponding to the customer number and the Part objects corresponding to the part numbers and store references to these objects instead of the customer and part numbers.
Your program should make sure that you do not have a situation where a customer number is used in an order that is not in the customers.dat file. If such a situation occurs, you should flag an error and skip the record. Similarly, you should flag a part number used in an order that is not in the parts.dat file and skip that entry.
The following are skeleton files for you to use in the assignment:
Customer.py
Customers.py
Part.py
Parts.py
Order.py
Orders.py
Driver.py
Sample run of the program is shown below:
mac-mini:p5-database raj$ python3 Driver.py data Welcome to Orders Database Program c, c cno, o ono, u ono pno discount, d ono pno, q: c CNO: 1111 CNAME: John Smith CITY: Atlanta CNO: 2222 CNAME: Alice Stewart CITY: Chicago CNO: 3333 CNAME: Doug Jones CITY: Montgomery c, c cno, o ono, u ono pno discount, d ono pno, q: c 1111 CNO: 1111 CNAME: John Smith CITY: Atlanta ORDERS: ATL-1000 ATL-1001 c, c cno, o ono, u ono pno discount, d ono pno, q: o ATL-1000 Order no: ATL-1000 Placed by: CNO: 1111 CNAME: John Smith CITY: Atlanta Order date: 12-10-2022 PNO PNAME PRICE QTY %DISCOUNT COST 1000 Nut 2.50 5 50 6.25 1001 Bolt 3.00 20 10 54.00 1004 Cylinder 8.00 15 15 102.00 TOTAL 162.25 c, c cno, o ono, u ono pno discount, d ono pno, q: o ATL-101 ATL-101 NOT FOUND c, c cno, o ono, u ono pno discount, d ono pno, q: o ATL-1001 Order no: ATL-1001 Placed by: CNO: 1111 CNAME: John Smith CITY: Atlanta Order date: 12-15-2022 PNO PNAME PRICE QTY %DISCOUNT COST 1000 Nut 2.50 25 20 50.00 1001 Bolt 3.00 20 20 48.00 1004 Cylinder 8.00 25 15 170.00 TOTAL 268.00 c, c cno, o ono, u ono pno discount, d ono pno, q: u ATL-1001 1004 50 Discount updated! c, c cno, o ono, u ono pno discount, d ono pno, q: o ATL-1001 Order no: ATL-1001 Placed by: CNO: 1111 CNAME: John Smith CITY: Atlanta Order date: 12-15-2022 PNO PNAME PRICE QTY %DISCOUNT COST 1000 Nut 2.50 25 20 50.00 1001 Bolt 3.00 20 20 48.00 1004 Cylinder 8.00 25 50 100.00 TOTAL 198.00 c, c cno, o ono, u ono pno discount, d ono pno, q: d ATL-1001 1000 Part deleted from order! c, c cno, o ono, u ono pno discount, d ono pno, q: o ATL-1001 Order no: ATL-1001 Placed by: CNO: 1111 CNAME: John Smith CITY: Atlanta Order date: 12-15-2022 PNO PNAME PRICE QTY %DISCOUNT COST 1001 Bolt 3.00 20 20 48.00 1004 Cylinder 8.00 25 50 100.00 TOTAL 148.00 c, c cno, o ono, u ono pno discount, d ono pno, q: q Bye! mac-mini:p5-database raj$ python3 Driver.py data Welcome to Orders Database Program c, c cno, o ono, u ono pno discount, d ono pno, q: o ATL-1001 Order no: ATL-1001 Placed by: CNO: 1111 CNAME: John Smith CITY: Atlanta Order date: 12-15-2022 PNO PNAME PRICE QTY %DISCOUNT COST 1001 Bolt 3.00 20 20 48.00 1004 Cylinder 8.00 25 50 100.00 TOTAL 148.00 c, c cno, o ono, u ono pno discount, d ono pno, q: q Bye! mac-mini:p5-database raj$