Question

In: Computer Science

Programming Assignment 5 Your work on the last project, the inventory ordering system, was so well...

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!")

Solutions

Expert Solution

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


Related Solutions

Assignment 1. Linear Programming Case Study Your instructor will assign a linear programming project for this...
Assignment 1. Linear Programming Case Study Your instructor will assign a linear programming project for this assignment according to the following specifications. It will be a problem with at least three (3) constraints and at least two (2) decision variables. The problem will be bounded and feasible. It will also have a single optimum solution (in other words, it won’t have alternate optimal solutions). The problem will also include a component that involves sensitivity analysis and the use of the...
Assignment 1. Linear Programming Case Study Your instructor will assign a linear programming project for this...
Assignment 1. Linear Programming Case Study Your instructor will assign a linear programming project for this assignment according to the following specifications. It will be a problem with at least three (3) constraints and at least two (2) decision variables. The problem will be bounded and feasible. It will also have a single optimum solution (in other words, it won’t have alternate optimal solutions). The problem will also include a component that involves sensitivity analysis and the use of the...
Instructions Use your solution from Programming Assignment 5 (or use your instructor's solution) to create a...
Instructions Use your solution from Programming Assignment 5 (or use your instructor's solution) to create a modular Python application. Include a main function (and a top-level scope check),and at least one other non-trivial function (e.g., a function that deals the new card out of the deck). The main function should contain the loop which checks if the user wants to continue. Include a shebang, and ID header, descriptive comments, and use constants where appropriate. Sample Output (user input in red):...
Instructions Use your solution from Programming Assignment 5 (or use your instructor's solution) to create a...
Instructions Use your solution from Programming Assignment 5 (or use your instructor's solution) to create a modular Python application. Include a main function (and a top-level scope check),and at least one other non-trivial function (e.g., a function that deals the new card out of the deck). The main function should contain the loop which checks if the user wants to continue. Include a shebang, and ID header, descriptive comments, and use constants where appropriate. Sample Output (user input in red):...
CS 1102 Unit 5 – Programming AssignmentIn this assignment, you will again modify your Quiz program...
CS 1102 Unit 5 – Programming AssignmentIn this assignment, you will again modify your Quiz program from the previous assignment. You will create an abstract class called "Question", modify "MultipleChoiceQuestion" to inherit from it, and add a new subclass of "Question" called "TrueFalseQuestion". This assignment will again involve cutting and pasting from existing classes. Because you are learning new features each week, you are retroactively applying those new features. In a typical programming project, you would start with the full...
Why does the economic concept of “cost shifting” work well in healthcare, but not so well...
Why does the economic concept of “cost shifting” work well in healthcare, but not so well with business?
In your OWN words, briefly explain prediction markets and why they work so well? Please explain.
In your OWN words, briefly explain prediction markets and why they work so well? Please explain.
Use R programming language to answer and please so show the code as well. A paper...
Use R programming language to answer and please so show the code as well. A paper manufacturer studied the effect of three vat pressures on the strength of one of its products. Three batches of cellulose were selected at random from the inventory. The company made two production runs for each pressure setting from each batch. As a result, each batch produced a total of six production runs. The data follow. Perform the appropriate analysis. Table is below Batch Pressure...
Periodic Inventory System If this business uses First in First out inventory system instead of Last...
Periodic Inventory System If this business uses First in First out inventory system instead of Last in Last out then what will the net income be for the month described below? Will it be Higher, lower, the same or unknown? Explain your reasoning. Cost of Goods Available for Sale: Date # of units $ per unit 1/1 Beginning Inventory 25 $50 1/4 Purchase of units 15 $45 1/20 Purchase of units 20 $42 1/30 Purchase of units 10 $37 Retail...
COSC 1436 Programming Assignment : Skill Practice Assignment 3 Your skill practice assignment this week will...
COSC 1436 Programming Assignment : Skill Practice Assignment 3 Your skill practice assignment this week will be programming challenge #6 on page 374 - Kinetic Energy In it you are asked to write a programing that returns the amount of kinetic energy the object has. You will ask the user to enter values for mass and velocity. You will need to create a function named kinetic Energy that accepts an object's mass (in kilograms) and velocity (in meters per second)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT