Language: Python First, define a Product class that includes all the information about a single product. a. You will need a constructor to initialize new instances. Objects of this class should have three instance variables: name, price, and quantity in-stock. b. Add a method to your class that takes an integer count and determines whether that many of the product are in stock. c. Add another method that takes a count and returns the total cost of that many of the product. d. Finally, add a method that takes a count and removes that many of the product from the stock. Next, replace the three product lists with a single list of Product instances. Modify the rest of the code to correctly use the attributes and methods of the Products in the list. product_names = ["Ultrasonic range finder", "Servo motor", "Servo controller", "Microcontroller Board", "Laser range finder", "Lithium polymer battery"                  ] product_prices = [2.50, 14.99, 44.95, 34.95, 149.99, 8.99] product_quantities = [4, 10, 5, 7, 2, 8] def print_stock():     print()     print("Available Products")     print("------------------")     for i in range(0, len(product_names)):         if product_quantities[i] > 0:             print(str(i)+")", product_names[i], "$", product_prices[i])     print() def main():     cash = float(input("How much money do you have? $"))     while cash > 0:         print_stock()         vals = input(             "Enter product ID followed by the quantity you wish to buy (or 'quit' to exit): ").split(" ")         if vals[0] == "quit":             break         prod_id = int(vals[0])         count = int(vals[1])         if product_quantities[prod_id] >= count:             if cash >= product_prices[prod_id] * count:                 product_quantities[prod_id] -= count                 cash -= product_prices[prod_id] * count                 print("You purchased", count, product_names[prod_id] + ".")                 print(f"You have ${cash:.2f} remaining.")             else:                 print("Sorry, you cannot afford that product.")         else:             print("Sorry, we are sold out of", product_names[prod_id]) if __name__ == '__main__':     main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Language: Python

  1. First, define a Product class that includes all the information about a single product. a. You will need a constructor to initialize new instances. Objects of this class should have three instance variables: name, price, and quantity in-stock. b. Add a method to your class that takes an integer count and determines whether that many of the product are in stock. c. Add another method that takes a count and returns the total cost of that many of the product. d. Finally, add a method that takes a count and removes that many of the product from the stock.
  2. Next, replace the three product lists with a single list of Product instances.
  3. Modify the rest of the code to correctly use the attributes and methods of the Products in the list.

product_names = ["Ultrasonic range finder", "Servo motor", "Servo controller", "Microcontroller Board", "Laser range finder", "Lithium polymer battery"
                 ]
product_prices = [2.50, 14.99, 44.95, 34.95, 149.99, 8.99]
product_quantities = [4, 10, 5, 7, 2, 8]


def print_stock():
    print()
    print("Available Products")
    print("------------------")
    for i in range(0, len(product_names)):
        if product_quantities[i] > 0:
            print(str(i)+")", product_names[i], "$", product_prices[i])
    print()


def main():
    cash = float(input("How much money do you have? $"))
    while cash > 0:
        print_stock()
        vals = input(
            "Enter product ID followed by the quantity you wish to buy (or 'quit' to exit): ").split(" ")
        if vals[0] == "quit":
            break
        prod_id = int(vals[0])
        count = int(vals[1])
        if product_quantities[prod_id] >= count:
            if cash >= product_prices[prod_id] * count:
                product_quantities[prod_id] -= count
                cash -= product_prices[prod_id] * count
                print("You purchased", count, product_names[prod_id] + ".")
                print(f"You have ${cash:.2f} remaining.")
            else:
                print("Sorry, you cannot afford that product.")
        else:
            print("Sorry, we are sold out of", product_names[prod_id])


if __name__ == '__main__':
    main()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education