JamesMadisonUniversity

Computer Science Department


CS 139 Lab:Health and Fitness Calculators - Part A


2 Creating Health.java

  1. Create a file Health.java either from the class template or your own.
  2. Create a function to calculate the BMI given a height in inches (integers) and a weight in pounds (double):
    1. Create a header for a public static function called, calculateBMI, which takes in a integer parameter and a double parameter in that order. Note that the formal parameters that store the height and weight will be a local variable available inside of the body of your function.
    2. Create the code in the "body" of the function that calculates the bmi. Declare additional variables in the function as needed.
    3. The BMI is calculated by multiplying weight (in pounds) by 705, then dividing by height (in inches) twice.
    4. Be sure to include a return statement that will return the calculated BMI value.
  3. Document your function using standard javadoc tags of @param to describe the incoming parameter and @return to describe the return value.
  4. Test your documentation by running the documenter function in jGrasp. You should see your tags and the documentation you have written. This will produce a whole bunch of files that when viewed as web pages yield something like this.
  5. Compile your Health.java program and correct any compile errors.

3 Adding the Target Heart Rate function

  1. In Health.java create another function which computes the target heart rate given a person's age. This function should return an int value representing the target exercise heart rate.
    1. Create a header for a public static function called calculateTargetHeartRate, which takes in one int parameters value, age.
    2. Create the body using the following calculation for the target heart rate. To calculate, subtract the person's age from 220. This is the maximum heart rate. The target is then 70% of this maximum.
    3. Be sure to include a return statement that will return the target heart rate.
  2. Make sure that the new function is properly documented.
  3. Compile the Health.java file.

4 Save your file per your instructors suggestion.


Updated 10/11/06 (nlh)