Problem Summary

A person would like to know how to determine his/her blood alcohol content (BAC). In Colorado, the legal driving limit is 0.08.

Blood alcohol content (BAC) is usually expressed as a percentage of ethanol in the blood in units of mass of alcohol per volume of blood or mass of alcohol per mass of blood. So, for example, in North America a BAC of 0.1 (0.1% or one tenth of one percent) means that there are 0.10 g of alcohol for every dL (deciliter) of blood.

A standard American drink contains 0.5 US fl oz (15 ml) of alcohol by volume, and is equivalent to:

12 oz of beer (5% alcohol)
5 oz of wine (12% alcohol)
1.5 oz shot of 80 proof liquor (40% alcohol)

This means that there are 14 grams of alcohol in one standard American drink.

Back in 1932, Swedish scientist Eric Widmark established the following formula for determining a persons initial BAC is:

BAC = (Alcohol consumed (in grams) / weight (in grams) x volume distribution (by gender)) x 100

In the original formulas, the volume distributions of alcohol in the blood by gender were fixed values. One value (0.68) was used for males, and another value (0.55) was used for females.

However, in 1986, English chemist Robert Forrest came up with a better way to calculate the volume distribution (by gender), taking the persons weight and height into account.

Male Volume Distribution = 1.0178 - ((0.012127 x weight) / height2)

Female Volume Distribution = 0.8736 - ((0.0124 x weight) / height2)

where weight is in kilograms and height is in meters

Using the above formulas allow a person to calculate their BAC immediately after drinking. The volume distribution is calculated first, and then the volume distribution is used in the Widmark formula.

However, most of the time, people consume drinks over a period of time. So the current BAC is further calculated by:

current BAC = BAC - (elapsed time in hours x metabolic rate)

The metabolic rate, characterizes the speed of alcohol absorption and elimination. Females demonstrated a higher average rate of elimination (mean, 0.017; range, 0.014 to 0.021) than males (mean, 0.015; range, 0.013 to 0.017). Due to these factors, and other differences between people, the BAC calculated in this program is only an ESTIMATE.

For this program, we will use the low end of the ranges.

Program Overview

In your last two Alice assignments, you:

  • Created programs that were broken down into multiple methods.
  • Used variables to store user input and calculation results.
  • Used parameters and return values to pass information between methods.

This assignment will require you to do the same things in Java.

This program will contain:

  • A main method to read the inputs from the user, convert some values, and call the other methods.
  • A method (1) to display a description of what the program will do.
  • A method (2) to calculate the volume distribution of alcohol in the body for men.
  • A method (3) to calculate the volume distribution of alcohol in the body for women.
  • A method (4) to calculate the current BAC.
  • A method (5) to display the results of the program.

Program Requirements

1. Create only one Java class for this program, named as follows:

LastnameJavaClassName
For example: SmithBACcalculator

2. The methods described above will be implemented within this class, as follows:

NOTE: All of these methods should have descriptive names that include a verb, describing the methods action.

Method 1: A method to display an explanation of what the program will do to the user.

  • This method will not have any parameters or a return value.

Methods 2 & 3: Two methods to calculate the volume distribution of alcohol, one method for men and one method for women. These methods will:

  • Have 2 parameters: weight in kilograms and height in meters
  • Compute the volume distribution of alcohol in the body using the formulas on page 1
    • Use a method from the Math library to compute the square.
  • Return a double value: the volume distribution of alcohol in the body

Method 4: A method to calculate the current BAC. This method will:

  • Have 5 parameters:
    • weight in pounds
    • volume distribution to use
    • metabolic rate to use
    • number of drinks consumed
    • number of hours elapsed
  • Define and use two local (non-static) constants, that contain the values for:
    • the number of grams in one pound (453.592)
    • the grams of alcohol in one drink (14)
  • Convert the weight to grams.
  • Calculate the grams of alcohol in the drinks consumed.
  • Compute the initial BAC using the Widmark formula on page 1.
  • Compute the current BAC using the last formula on page 1.
  • Return a double value: the current BAC.

Method 5: A method to display the results, with no return value. This method will:

  • Have 4 parameters:
    • number of drinks consumed
    • number of hours elapsed
    • current male BAC
    • current female BAC
  • Use the println and printf statements to:
    • Display a few blank lines before displaying any output
    • Display the output, exactly as shown in the sample below.
      Both BAC values should be displayed to 3 decimal places, and should line up.
    • Display one final blank line.

3. Within the main method, write the Java code to:

NOTE: The main method will be defined first, at the top of the class, before all the other methods.

  • Define and use four local (non-static) constants, that contain the values for:
    • the number of pounds in one kilogram (2.20462)
    • the number of inches in one meter (39.3701)
    • the metabolic rate for men (0.015)
    • the metabolic rate for women (0.014)
  • Call method 1 to display the program description.
  • Prompt for (using descriptive prompts) and read the user inputs (height in inches, weight in pounds, number of drinks consumed, number of hours elapsed while drinking).

    Sample Display and Input from main method
    This program implements a Blood Alcohol Content (BAC) Calculator

    Given a drinker's weight and height, and the number of drinks consumed over how many hours, it will compute the person’s approximate current blood alcohol content.>

    Please enter drinker's height (in inches): 66
    Please enter the drinker's weight (in pounds): 150
    How many drinks were consumed? 4
    How many whole hours have elapsed since drinking began? 2
  • Convert the weight to kilograms and the height to meters, and store the results into new variables.
  • Call the volume distribution calculations methods (methods 2 and 3) to separately compute the volume distribution for men and for women, and save the results returned from each.
  • Call the current BAC calculation method (method 4) twice:
    • The first call should pass in the volume distribution computed for men and the metabolic rate for men.
    • The second call should pass in the volume distribution computed for women and the metabolic rate for women.
    • Save the results returned from each call.
  • Call the method to display the results (method 5) as shown below.

    Sample Results Output
    After drinking 4 drinks, in 2 hours:
    Current BAC for a male will be approximately 0.084
    Current BAC for a female will be approximately 0.116

4. You must also define and use:

  • Local variables for each input or computed value, defined using descriptive names and appropriate data types.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.