Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3: Inheritance beverage class implementation >>> bev = Beverage('Soda', True) >>> bev is not None True >>> bev.hot True >>> isinstance(bev, Beverage) True >>>

Python 3: Inheritance beverage class implementation image text in transcribed

>>> bev = Beverage('Soda', True)

>>> bev is not None

True

>>> bev.hot

True

>>> isinstance(bev, Beverage)

True

>>> print(bev)

Hot Soda

>>> bev2 = Beverage('Tea', False)

>>> print(bev2)

Cold Tea

>>> coff = Coffee(2, 3)

>>> print(coff)

Coffee with 2 sugars and 3 creams

>>> isinstance(coff, Beverage)

True

>>> coff.ingredients["sugars"]==2

True

>>> soda = Soda(False)

>>> print(soda)

Cold Soda

>>> coke = Coke(False)

>>> coke.is_carbonated

True

>>> print(coke)

Could not care less for Coke

>>> another_coke = Coke(True)

>>> print(another_coke)

Cold Coke is my favorite

For this question, you are going to design your own classes with minimum amount of hints Implement a Beverage class which takes in a name, and whether a beverage is hot o You will need init constructor method which takes as arguments name which is a string and hot which is a Boolean o name and hot are instance attributes . Implement a subclass, Coffee which is a Beverage o Its constructor should take two new arguments sugars and cream which are both ints. o Coffee is always hot o There is additional instance attribute that only belongs to the instance of class Coffee ingredients which is implemented as a dictionary, with keys "sugars" and "creams". Make sure you initialize it properly in your constructor . Implement another subclass Soda which is-a Beverage o The constructor should take one new argument is_carbonated that indicates if soda is carbonated o is carbonated is a new instance attribute o Soda is always cold Implement a Coke class which is-a Soda o The constructor should take one new argument my_favorite that indicates if you like Coke o Coke is always cold o Coke is always carbonated In each class, implement_str__method which is implicitly called by print () and which outputs logical representations of your beverages Please refer to the sample doctests below to match you output with ours Note: ok requires you to write the tests for every class member function. Please write tests under each individual member function's docstring

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

What is the purpose of the OFCCP?

Answered: 1 week ago

Question

LO2 Distinguish among three types of performance information.

Answered: 1 week ago