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...
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.
(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...
Create a java program that: - Has a class that defines an exception -Have that exception...
Create a java program that: - Has a class that defines an exception -Have that exception throw(n) in one method, and be caught and handled in another one. -Has a program that always continues even if incorrect data is entered by the user -has a minimum of 2 classes in it
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game...
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game that involves betting on the sum of two dice. The player will start out with some initial total amount of money. During each round, the player can bet some money that the sum of the two dice will be equal to a certain number. If the player wins the bet, that player adds the amount of the bet to his or her current total....
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
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