Menu

[Solved] Language Python Class Name Coffee Method Name Init Parameters Self Iced Boolean Size Str N Q37209162

Language: Python

Class name: Coffee
Method name : __init__
Parameters : self, iced (boolean), size (str), name (str),num_cream (int), num_sugars (int, default to 0)
Returns: a Coffee object

Description: You’re a barista, and you want to write a customPython class to help you keep track of the Coffees customers order.Write a class called Coffee that has an __init__ method that takesin a boolean describing whether the Coffee is iced or not, a stringrepresenting the Coffee’s size, a string representing the name ofthe person who ordered the Coffee, and an int representing thenumber of creams in the Coffee. There should also be an optionalint parameter representing the number of sugars; if a value is notpassed in for this attribute, initialize it to 0.

Method name : __eq__
Parameters : self (Coffee object), other (Coffee object)

Returns: boolean

Description: Write a method to override the equals operator foryour Coffee class. It should take in two Coffee objects, self andanother Coffee, and return True if the iced, num_cream, andnum_sugars attributes are the same, and False otherwise.

Test Cases :
>>> myDrink = Coffee(True, “venti”, “Christine”, 2,2)
>>> yourDrink = Coffee(False, “supersize”, “Melinda”, 1,0) >>> myOtherDrink = Coffee(True, “grande”, “Chris”, 2,2) >>> myDrink == myOtherDrink
True
>>> myDrink == yourDrink
False

Method name : mix
Parameters : self (Coffee object), other (Coffee object) Returns: aCoffee object

Description: As a barista, you’re always looking for ways toimprove the drinks you serve. You’ve been experimenting with mixingtwo Coffees together to make a better Coffee. Write another methodfor your Coffee class that takes in two Coffee objects – Coffee Aand Coffee B – and returns a new Coffee object whose iced attributeis True if both Coffee A and B’s iced attributes are True (andFalse otherwise). The method should return a new Coffee objectwhose size attribute is whichever of Coffee A and B’s sizeattributes has more letters (assume there won’t be any ties forlonger size name). The new Coffee object’s num_sugars and num_creamattributes should be whichever of Coffee A and B’s correspondingattributes is larger. The new Coffee’s name attribute should be“Mystery”.

Test Cases :
>>> myDrink = Coffee(True, “venti”, “Christine”, 2,2)
>>> yourDrink = Coffee(False, “supersize”, “Melinda”, 1,0) >>> newDrink = myDrink.mix(yourDrink)
>>> print(newDrink.iced)
False
>>> print(newDrink.size)
supersize
>>> print(newDrink.name)
Mystery
>>> print(newDrink.num_cream)
2
>>> print(newDrink.num_sugars)
2

Expert Answer


Answer to Language: Python Class name: Coffee Method name : __init__ Parameters : self, iced (boolean), size (str), name (str), nu… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *