Please use Python for this question. Make sure the code is formatted properly as well. Write a Pizza class so that this client code works. Please note that it is ok if the toppings are listed in a different order. The Pizza class should have two attributes(data items): size – a single character str, one of ‘S’,’M’,L” toppings – a set containing the toppings.  If you don’t remember how to use a set, make sure you look it up in the book.  Please note that toppings may be listed in a different order, but hw2TEST.py takes that into account.  The Pizza class should have the following methods/operators): __init__ - constructs a Pizza of a given size (defaults to ‘M’) and with a given set of toppings (defaults to empty set).    I highly recommend you look at the Queue class in the book to see how to get this to work correctly. setSize – set pizza size to one of ‘S’,’M’or ‘L’ getSize – returns size addTopping – adds a topping to the pizza, no duplicates, i.e., adding ‘pepperoni’ twice only adds it once removeTopping – removes a topping from the pizza price – returns the price of the pizza according to the following scheme:           ‘S’: $6.25 plus 70 cents per topping           ‘M’: $9.95 plus $1.45 per topping           ‘L’: $12.95 plus $1.85 per topping __repr__ - returns representation as a string – see output sample above.  Note that toppings may be listed in a different order. __eq__ - two pizzas are equal if they have the same size and same toppings (toppings don’t need to be in the same order)   Output for this question: >>> pie = Pizza() >>> pie Pizza('M',set()) >>> pie.setSize('L') >>> pie.getSize() 'L' >>> pie.addTopping('pepperoni') >>> pie Pizza('L',{'pepperoni'}) >>> pie.addTopping('anchovies') >>> pie.addTopping('mushrooms') >>> pie==Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'}) True >>> pie.addTopping('pepperoni') >>> pie==Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'}) True >>> pie.removeTopping('anchovies') >>> pie==Pizza('L',{'mushrooms', 'pepperoni'}) True >>> pie.price() 16.65 Note: In the following code, p==p2 shoudl be False. If True than they are sharing the same set (or list) of toppings You need to make sure that the set() constructor is called in all cases in the body of the Pizza constructor. See course notes for the Queue class. >>> p = Pizza() >>> p2 = Pizza() >>> p.addTopping('mushroom') >>> p2.addTopping('onion') >>> p.addTopping('mushroom') >>> p Pizza('M',{'mushroom'}) >>> p2 Pizza('M',{'onion'}) >>> p==p2 # see note in TEST file False >>> # reroute stdin # code below directs input to be received from above should not cause an error >>> import sys >>> si = sys.stdin >>> sys.stdin = open('hw8TEST.py')

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

Please use Python for this question. Make sure the code is formatted properly as well.

Write a Pizza class so that this client code works. Please note that it is ok if the toppings are listed in a different order.

The Pizza class should have two attributes(data items):

size – a single character str, one of ‘S’,’M’,L”

toppings – a set containing the toppings.  If you don’t remember how to use a set, make sure you look it up in the book.  Please note that toppings may be listed in a different order, but hw2TEST.py takes that into account. 

The Pizza class should have the following methods/operators):

__init__ - constructs a Pizza of a given size (defaults to ‘M’) and with a given set of toppings (defaults to empty set).    I highly recommend you look at the Queue class in the book to see how to get this to work correctly.

setSize – set pizza size to one of ‘S’,’M’or ‘L’

getSize – returns size

addTopping – adds a topping to the pizza, no duplicates, i.e., adding ‘pepperoni’ twice only adds it once

removeTopping – removes a topping from the pizza

price – returns the price of the pizza according to the following scheme:

          ‘S’: $6.25 plus 70 cents per topping
          ‘M’: $9.95 plus $1.45 per topping
          ‘L’: $12.95 plus $1.85 per topping

__repr__ - returns representation as a string – see output sample above.  Note that toppings may be listed in a different order.

__eq__ - two pizzas are equal if they have the same size and same toppings (toppings don’t need to be in the same order)

 

Output for this question:


>>> pie = Pizza()
>>> pie
Pizza('M',set())
>>> pie.setSize('L')
>>> pie.getSize()
'L'
>>> pie.addTopping('pepperoni')
>>> pie
Pizza('L',{'pepperoni'})
>>> pie.addTopping('anchovies')
>>> pie.addTopping('mushrooms')
>>> pie==Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})
True
>>> pie.addTopping('pepperoni')
>>> pie==Pizza('L',{'anchovies', 'mushrooms', 'pepperoni'})
True
>>> pie.removeTopping('anchovies')
>>> pie==Pizza('L',{'mushrooms', 'pepperoni'})
True
>>> pie.price()
16.65

Note: In the following code,
p==p2 shoudl be False. If True
than they are sharing the same set (or list) of toppings

You need to make sure that the set() constructor is
called in all cases in the body of the Pizza
constructor. See course notes for the Queue class.

>>> p = Pizza()
>>> p2 = Pizza()
>>> p.addTopping('mushroom')
>>> p2.addTopping('onion')
>>> p.addTopping('mushroom')
>>> p
Pizza('M',{'mushroom'})
>>> p2
Pizza('M',{'onion'})
>>> p==p2 # see note in TEST file
False
>>>
# reroute stdin #

code below directs input to be received from above
should not cause an error

>>> import sys
>>> si = sys.stdin
>>> sys.stdin = open('hw8TEST.py')

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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