In: Computer Science
Objective:
Create a program that has a class to represent a cup of coffee that combines the properties: name and caffeine content. The class should also have a method that calculates the number of cups that would be maximally risky to consume in a short period of time. The program should create two instances of the class coffee where the user enters their properties and should output the amount of coffees that consumed would be risky.
Requirements:
Write a class called Coffee with the following
Next write a test class
Example Output:
Let’s Coffee!!!1!11!!ONE!!!1!
What’s the name of the first coffee?
Double Triple Loca Mocha Latte Venti Grande
What’s the caffeine content?
150
What’s the name of the second coffee?
Waffle House Coffee
What’s the caffeine content?
100
It would take 20.0 Double Triple Loca Mocha Latte Venti Grande coffees before it’s dangerous to drink more.
It would take 30.0 Waffle House Coffee coffees to before it’s dangerous to drink more.
Class Coffee and instance variables Name and Caffiene_content is declared. there is a check for Caffeine_content and set the value. Accessor/get function returns the calculated ammount.
CODE:
class Coffee():
# setter function
def Mutator(self,Name,Caffeine_content):
# instance variables
self.Name = Name
if 50 <= Caffeine_content <= 300:
self.Caffeine_content = Caffeine_content
else:
self.Caffeine_content = 0
# getter function
def Accessor(self):
if self.Caffeine_content == 0:
return "Risky Amount"
else:
cups_amount = 180.0/(( self.Caffeine_content / 100.0)*6.0)
return "It would take {} {} coffees before it’s dangerous to drink more.".format(round(cups_amount,1),self.Name)
print("Let’s Coffee!!!1!11!!ONE!!!1!")
name1 = input("What’s the name of the first coffee?")
caffine1 = int(input("What’s the caffeine content?"))
name2 = input("What’s the name of the second coffee?")
caffine2 = int(input("What’s the caffeine content?"))
# Instance 1 of class Coffee
obj1 = Coffee()
obj1.Mutator(name1,caffine1)
print (obj1.Accessor())
# Instance 2 of class Coffee
obj2= Coffee()
obj2.Mutator(name2,caffine2)
print (obj2.Accessor())