CS 139 Lab:Health and Fitness
Calculators - Part A
2 Creating Health.java
Create a file Health.java either from the
class template or your own.
Create a function to calculate the BMI given a height in inches
(integers) and a weight in pounds (double):
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.
Create the code in the "body" of the function that calculates the
bmi. Declare additional variables in the function as needed.
The BMI is calculated by multiplying weight (in pounds) by 705,
then dividing by height (in inches) twice.
Be sure to include a return statement that will return the calculated BMI value.
Document your function using standard javadoc tags of @param to describe the incoming parameter and
@return to describe the return
value.
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.
Compile your Health.java program and correct
any compile errors.
3 Adding the Target Heart Rate function
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.
Create a header for a public static
function called calculateTargetHeartRate,
which takes in one int parameters value, age.
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.
Be sure to include a return statement that will return the target heart rate.
Make sure that the new function is properly documented.