the provided Book class in the file hw05_q2.py, create a container class called ShoppingList to store a list of books for a semester's worth of classes.  Your ShoppingList class should primarily consist of a list of Book objects and should support the following methods: Constructor that takes a list of course designators (eg., "CSCI 1133") and creates a list of Book objects using the provided constructor in the Book class and the book information in the file catalog.py.  Your constructor should have the signature __init__(self, courses). Overloaded addition operator that allows you to add Book objects to a ShoppingList using '+' Overloaded subtraction operator that allows you to remove Book objects from a ShoppingList using '-' A get_total_price() function that returns a sum of the prices of all books on the shopping list. You should use the same catalog list for testing as you used in problem 1.  Save your ShoppingList class in the same hw05_q2.py file as the provided Book class.   hw05_q2.py file:

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

Using the provided Book class in the file hw05_q2.py, create a container class called ShoppingList to store a list of books for a semester's worth of classes.  Your ShoppingList class should primarily consist of a list of Book objects and should support the following methods:

  • Constructor that takes a list of course designators (eg., "CSCI 1133") and creates a list of Book objects using the provided constructor in the Book class and the book information in the file catalog.py.  Your constructor should have the signature __init__(self, courses).
  • Overloaded addition operator that allows you to add Book objects to a ShoppingList using '+'
  • Overloaded subtraction operator that allows you to remove Book objects from a ShoppingList using '-'

A get_total_price() function that returns a sum of the prices of all books on the shopping list.

You should use the same catalog list for testing as you used in problem 1.  Save your ShoppingList class in the same hw05_q2.py file as the provided Book class.

 

hw05_q2.py file:

import catalog

class Book:

#Constructor takes a dictionary object to initialize member values. Subject is a
#string representing the 3-4 letter department designator eg., CSCI
def __init__(self, subject, book_info):
self.title = book_info['textbook']
self.price = book_info['price']
self.class_uses = [subject + ' ' + book_info['number']]

def book_title(self):
return self.title

def book_price(self):
return self.price

def book_classes_use(self):
return self.class_uses

catalog file:

csci = {"abbreviation":"CSCI", "department":"Computer Science",
"classes": [{"number": "1133", "textbook": "Programming in Python", "price":60.00},
{"number": "3081W", "textbook": "UML Distilled", "price":45.00},
{"number": "4041", "textbook": "Introduction to Algorithms", "price":70.00},
{"number": "4511W", "textbook": "Artificial Intelligence", "price": 159.99},
{"number": "5511", "textbook": "Artificial Intelligence", "price": 159.99}]}

chen = {"abbreviation":"CHEN", "department":"Chemical Engineering",
"classes": [{"number": "3101", "textbook":"Chemical, Biochemical, & Engineering Thermodynaics", "price":78.95},
{"number": "3006", "textbook":"Separation Process Principles", "price":106.50},
{"number": "4214", "textbook":"Polymer Chemistry", "price":135.00},
{"number": "4708", "textbook":"Chemical Rate Processes", "price":211.25},
{"number": "8101", "textbook":"Incompressible Flow", "price":175.00}]}

chem = {"abbreviation":"CHEM", "department":"Chemistry",
"classes": [{"number": "1907", "textbook":"Food Lab", "price":33.00},
{"number": "2301", "textbook":"Organic Chemistry", "price":40.00},
{"number": "4021", "textbook":"Essentials of Computational Chemistry", "price":80.00},
{"number": "4701", "textbook":"Inorganic Chemistry", "price":260.00},
{"number": "8552", "textbook":"Principles of Quantum Mechanics", "price":102.65}]}

biol = {"abbreviation": "BIOL", "department":"Biology",
"classes":[{"number": "2012", "textbook":"Animal Diversity", "price":177.50},
{"number": "3272", "textbook":"Analysis of Biological Data", "price":168.80},
{"number": "4003", "textbook":"Genetics", "price": 44.25},
{"number": "4004", "textbook":"Molecular Cell Biology", "price":167.50},
{"number": "5309", "textbook":"Molecular Ecology", "price":151.00}]}

ling = {"abbreviation": "LING", "department":"Linguistics",
"classes":[{"number":"1912", "textbook":"Art of Language Invention", "price": 12.95},
{"number": "3601", "textbook":"Trask's Historical Linguistics", "price": 61.80},
{"number": "4201", "textbook":"Syntax: A Generative Introduction", "price":33.50},
{"number": "4302W", "textbook":"Introductory Phonology", "price":40.40},
{"number":"5206", "textbook":"Pragmatics", "price":33.95}]}

bskt = {"abbreviation": "BSKT", "department":"Basket Weaving",
"classes":[{"number": "1091", "textbook": "Basket Arts", "price":101.50},
{"number": "2223", "textbook": "Physics of Basket Weaving", "price":68.33},
{"number": "3104", "textbook": "Underwater Basket Weaving", "price":149.95},
{"number": "5103", "textbook": "Basket Weaving in Midair", "price": 43.10},
{"number": "8001", "textbook": "Zero Gravity Weaving Arts", "price":50.50}]}

catalog = [csci, chen, chem, biol, ling, bskt]

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Passing Array as Argument
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