In: Computer Science
Write a Java program that calculates the blood alcohol content of someone drinking Jagerbombs. Assume that there are 0.55 ounces of alcohol in one Jagerbomb. Pick values of your own choosing for the number of drinks and the weight. Also output whether or not the person would be legally intoxicated in your state.
The following formula gives a rough estimate of your blood alcohol content (BAC) and is derived from formulas posted by the National Highway Traffic safety administration:
BAC = (4.136 x numDrinks x ouncesAlcohol) / (weight)
numDrinks is the number of drinks ingested.
ouncesAlcohol is the number of ounces of alcohol per drink
weight is the weight of the drinker in pounds
Note: that this formula gives only a rough estimate and doesn’t include your metabolism, time spent drinking, gender differences, etc.
SOURCE CODE:
import java.util.*;
import java.lang.*;
import java.io.*;
class BAC
{
public static void main (String[] args) throws
java.lang.Exception
{
Scanner input=new Scanner(System.in);
int numDrinks;
double weight;
System.out.println("Enter the number of DRINKS: ");
numDrinks=input.nextInt(); //taking input from user the number of
drinks..
System.out.println("Enter your WEIGHT in pounds: ");
weight=input.nextDouble(); //taking input from user the weight in
pounds..
double BAC= (4.136*numDrinks*0.55)/weight; //calculating BAC as per the formula given in the question..
System.out.println("Blood alcohol content is: "+BAC); //printing the values of BAC..
//In our state we have taken BAC<=0.16 as legally intoxic person..
if(BAC<=0.16) //you can change the legal value of BAC
according to your state..
{
System.out.println("The person is legally intoxicated.");
}
else
{
System.out.println("The person is not legally intoxicated.");
}
}
}
OUTPUT:
NOTE: I have taken the legal value BCA as less than or equal to 0.12. You can take its legal value as per your state and as class name was not given I have taken it myself i.e. "BCA"
I have mentioned comments in the code wherever necessary. Please copy entire code and save it with "BCA.java" then compile and run.
HOPE IT HELPS..!!!!
For any query please feel free to comment..
Thanks.