This is similar to programming challenge 3, page 188 of our book. (in the international version it is page 212)
You are free to give to BodyMass any instance variables you may think it needs. They can be public or private, and have any name you choose.
setWeight
returns: nothing
arguments: a double
what it does: it somehow stores the value of its argument in the class BodyMass. We will call this value weight in the rest of the specification.
setHeight
returns: nothing
arguments: a double
what it does: it somehow stores the value of its argument in the class BodyMass. We will call this value height in the rest of the specification.
stats
returns: nothing
arguments: none
what it does: it uses the values of weight and height we mentioned earlier.
Example1: if weight is 220 pounds and height is 73 inches, then stats prints the following:
weight: 220.0
height: 73.0
bmi: 29.022330643647965
bmi indicates person is: overweight
bmi represents the body mass index, and it is computed by the following formula;
BMI = Weight x 703/Height2
If the BMI is between 18.5 and 25 the weight of the person is considered "optimal"
if the BMI is less than 18,5, the person is underweight
if the BMI is greater than 25, the person is overweight.
Example2: if weight is 180 pounds and height is 74 inches, then stats prints the following:
weight: 180.0
height: 74.0
bmi: 23.10810810810811
bmi indicates person is: optimal
Example3: if weight is 130 pounds and height is 74 inches, then stats prints the following:
weight: 130.0
height: 74.0
bmi: 16.68918918918919
bmi indicates person is: underweight