Question

In: Computer Science

Objective: Create a program that has a class to represent a cup of coffee that combines...

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

  • Instance Variables
    • Name
    • Caffeine content. Coffee is around 50 to 300mg of caffeine
  • Methods
    • Accessors and Mutators for the instance variables
      • Make sure in the mutator for the caffeine content contains a check to make sure the value is between 50 and 300 inclusively
    • RiskyAmount
      • Calculates the number of coffee’s to before it would be dangerous to consume more within a short time frame, and it is based on this formula:

        cups amount = 180.0/((caffeine content / 100.0)*6.0)
      • Returns the number of coffees it would take before they could be at a health risk.

Next write a test class

  • Contains a main method
  • Creates two instances of the type Coffee
  • Have the user enter in the names and caffeine contents for both
  • Print out the results

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.

Solutions

Expert Solution

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())

Related Solutions

Objective: Create a program that has a class to represent a cup of coffee that combines...
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...
Before each class, I either drink a cup of coffee, a cup of tea, or a...
Before each class, I either drink a cup of coffee, a cup of tea, or a cup of water. The probability of coffee is 0.7, the probability of tea is 0.2, and the probability of water is 0.1. If I drink coffee, the probability that the lecture ends early is 0.3. If I drink tea, the probability that the lecture ends early is 0.2. If I drink water, the lecture never ends early. 1) What’s the probability that I drink...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks: • Set the number of each of the letter grades A, B, C, D, and F. • Read the number of each of the letter grades A, B, C, D, and F. • Return the total number of grades. • Return the percentage of...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
A person eats a grapefruit and drinks a large cup of coffee AND a cup of...
A person eats a grapefruit and drinks a large cup of coffee AND a cup of orange juice for breakfast (I guess they were thirsty). All these items are acidic! How will the respiratory and renal systems respond? Include a description of how the respiratory system detects the error signal and activates its response.
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
In a coffee-cup calorimeter experiment, if we ignored the heat lost to the Styrofoam cup and...
In a coffee-cup calorimeter experiment, if we ignored the heat lost to the Styrofoam cup and the air, does this cause the heat gained by the total solution at the end to be too big or too small. Could you please explain.
A machine in the student lounge dispenses coffee. The average cup of coffee is supposed to...
A machine in the student lounge dispenses coffee. The average cup of coffee is supposed to contain 7.0 ounces. A random sample of eight cups of coffee from this machine show the average content to be 7.4 ounces with a standard deviation of 0.70 ounce. Do you think that the machine has slipped out of adjustment and that the average amount of coffee per cup is different from 7 ounces? Use a 5% level of significance. What is the value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT