Problem

Scientists estimate that roughly 10 grams of caffeine consumed at one time is a lethal ove...

Scientists estimate that roughly 10 grams of caffeine consumed at one time is a lethal overdose. Write a program with a variable that holds the number of milligrams of caffeine in a drink and outputs how many drinks it takes to kill a person. A 12-ounce can of cola has approximately 34 mg of caffeine, while a 16-ounce cup of coffee has approximately 160 mg of caffeine.

Step-by-Step Solution

Solution 1

Program Plan:

• Declare integer variables that hold the milli grams of caffeine in cola and coffee.

• Initialize one gram is 1000 milligrams as one_gram=1000

• Covert 10 grams into the milli grams and divide by the number of grams of caffeine the cola drink contains.

• Covert 10 grams into the milli grams and divide by the number of grams of caffeine the coffee drink contains.

• Print number of drinks of cola and number of drinks of coffee to kill a person when consumed at once.

Program Code

/********************************************************

* The java program determines the number of cola drinks*

* and coffees when consumed at once. Then prints *

* the number of cola drinks and number of coffees on *

* console. *

********************************************************/

//PP10.java

public class PP10

{

public static void main(String[] args)

{

//initialize a variable one_gram=1000mg

int one_gram=1000;

/*integer variable that holds 34 mg of the caffeine

in 12 ounce cola */

int caffeine_in_12_ounce_cola=34;

/*integer variable that holds 160 mg of the caffeine

in 16 ounce coffee */

int caffeine_in_16_ounce_coffee=160;

Calculate the number of drinks of cola and caffeine.

/* Covert the 10 grams into the milli grams and divide

by the number of grams that drink contains caffeine.*/

double num_cola_drinks

=10.0*one_gram/caffeine_in_12_ounce_cola;

double num_coffee_drinks=

10.0*one_gram/caffeine_in_16_ounce_coffee;

/* print the number of colas when consumed at once will

kill a person*/

System.out.println("The number of cola drinks to kill a person consumed at once : "+num_cola_drinks);

/* print the number of coffee when consumed at once will

kill a person */

System.out.println("The number of coffees to kill a person

consumed at once : "+num_coffee_drinks);

}//end of main

}//end of the class PP10

Sample output:

The number of cola drinks to kill a person consumed at once : 294.11764705882354

The number of coffees to kill a person consumed at once : 62.5

Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 1
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT