In: Computer Science
Programming Assignment 5
Your work on the last project, the inventory ordering system, was so well received that your boss has asked you to write a new program for the firm. She mentions that she’s heard a lot about “Object Oriented Programming” and wants you to create a database of part’s suppliers that the company will use to source new inventory from. She mentions that there have been a lot of new entrants into the market and its important that you source the new widgets and sprockets at the best cost possible! From speaking with her you realize that you’ll need three new class definitions – a class that models a supplier, a class that represents a part, and class that will contain information about all these suppliers.
The parts class will need to contain the following information:
1. Part name
2. Part cost
The parts class will need to contain the following methods:
1. An init method that lets the user set the name and cost of the part
The supplier class will need to contain the following information:
1. The company name
2. A list of the parts the company supplies
The supplier class will need the following methods:
1. An init method to set the company name
2. A method that lets the user add a part to the list of parts a company supplies
3. A method that takes a part argument and returns the cost of that part.
4. A method that takes a part argument and returns a Boolean if the part is supplied by the company (True if it does, False if it does not).
The database class will need the following data:
1. A list of suppliers
The database class will need the following methods:
1. An init method to initialize the database
2. A method to add a supplier
3. A method to find the lowest cost for a part. The input will be a part name, and the output will be two values: the name of the supplier, and the cost. If the part is not sold by any suppliers, return False, False. Unlike in other programs – you do not need to write the code for user input, input validation, or output – you need only to write the classes! The company has supplied the program to load in the data and get the data from the classes, you need only to define the classes (and test with the supplied program of course)!
Sample Input/Output
Enter supplier name, or quit to exit: World Parts, Inc
Part info should be entered in the following format: name, price
Enter part info, or quit to exit: gizmo, 1.99
Enter part info, or quit to exit: sprocket, 3.12
Enter part info, or quit to exit: quit
Enter supplier name, or quit to exit: ABC Manufacturing
Part info should be entered in the following format: name, price
Enter part info, or quit to exit: sprocket, 3.09
Enter part info, or quit to exit: gizmo, 2.34
Enter part info, or quit to exit: dodad, 13.99
Enter part info, or quit to exit: quit
Enter supplier name, or quit to exit: quit
Supplier database complete!
Please enter in a part name or quit to exit: gizmo
Part gizmo is available for the best price at World Parts, Inc. Price: $1.99
Please enter in a part name or quit to exit: sprocket
Part sprocket is available for the best price at ABC Manufacturing. Price: $3.09
Please enter in a part name or quit to exit: dodad
Part dodad is available for the best price at ABC Manufacturing. Price: $13.99
Please enter in a part name or quit to exit: quit T
hank you for using the price database!
Additional requirements
1. You MUST use modules, you need to write your 3 classes in 3 separate Python files named database.py, part.py and supplier.py
2. Do NOT modify the supplied Python code – I will test your files with my own Python code – if you have to change the provided Python code to get your classes to work, you’ll lose points.
3. Submit only the 3 python files – part.py, supplier.py and database.py
4. Each Python file must have a program header!
Tips
1. The provided code does all the input/output for this program. You only need to write the code for the 3 classes.
2. Some of the methods for the 3 classes need to be of a specific format or the supplied program will not work – these are the init methods for Suppler and Database, and add_part, add_supplier, and find_part. Make sure you have those methods defined in your program and that their signature matches what the provided code expects.
3. Write the classes from simple to more complex – start with Part, then Supplier, then Database.
The following is a sample code
import database
import supplier
import part
supplier_database = database.Database()
while True:
data = input("Enter supplier name, or quit to exit: ")
if data == "quit":
break
s = supplier.Supplier(data)
print("Part info should be entered in the following format: name, price")
while True:
part_info = input("Enter part info, or quit to exit: ")
if part_info == "quit":
print()
break
try:
name, price = part_info.split(",")
price = float(price)
except:
print("Error input - Part info should be entered in the following format: name, price - please try again")
continue
s.add_part(name, price)
supplier_database.add_supplier(s)
print("\n\nSupplier database complete!\n")
while True:
data = input("Please enter in a part name or quit to exit: ")
if data == "quit":
break
supplier, price = supplier_database.find_part(data)
if supplier == False:
print("Error part does not exist in database")
else:
print(f"Part {data} is available for the best price at {supplier}. Price: ${price:.2f}")
print("\nThank you for using the price database!")
part.py
"""
Created on Sat Oct 31 09:18:06 2020
@author: ranjan
"""
class Part:
def __init__(self, name, cost):
self.name = name
self.cost = cost
supplier.py
"""
Created on Sat Oct 31 09:19:20 2020
@author: ranjan
"""
import part
class Supplier:
def __init__(self, name):
self.name = name
self.parts = []
def add_part(self, name, price):
self.parts.append(part.Part(name, price))
def find_cost(self, name):
for p in
self.parts:
if p.name == name:
return p.cost
def isSupplied(self, name):
for pa in
self.parts:
if name==pa.name:
return True
return False
database.py
"""
Created on Sat Oct 31 09:29:12 2020
@author: ranjan
"""
import sys
class Database:
def __init__(self):
self.suppliers =
[]
def add_supplier(self, supp):
self.suppliers.append(supp)
def find_part(self, part_name):
minimum =
sys.maxsize
s = None
for supp in
self.suppliers:
if
supp.isSupplied(part_name):
cost = supp.find_cost(part_name)
if cost < minimum:
minimum = cost
s = supp
if s is not None:
return s.name, cost
else:
return False
driver.py
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 31 09:12:10 2020
@author: ranjan
"""
import database
import supplier
supplier_database = database.Database()
while True:
data = input("Enter supplier name, or quit to
exit: ")
if data == "quit":
break
s = supplier.Supplier(data)
print("Part info should be entered in the
following format: name, price")
while True:
part_info = input("Enter
part info, or quit to exit: ")
if part_info ==
"quit":
print()
break
try:
name, price = part_info.split(",")
price = float(price)
except:
print("Error input - Part info should be entered in the following
format: name, price - please try again")
continue
s.add_part(name,
price)
supplier_database.add_supplier(s)
print("\n\nSupplier database
complete!\n")
while True:
data = input("Please enter in a part name or
quit to exit: ")
if data == "quit":
break
supplier, price =
supplier_database.find_part(data)
if supplier == False:
print("Error part does
not exist in database")
else:
print(f"Part {data} is
available for the best price at {supplier}. Price:
${price:.2f}")
print("\nThank you for using the price database!")
i hope it helps..
If you have any doubts please comment and please don't dislike.
PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME