Lab Exercise for Computing Body Mass Index and Determining Weight Category in Java, Exercises of Computer Science

An exercise for students in csci 1301 lab to enhance their java application from lab #4. The exercise requires students to modify the main method of the bmi class to validate user input for weight and height, compute bmi score, and determine weight category based on the score. The document also includes examples and hints.

Typology: Exercises

2019/2020

Uploaded on 06/08/2020

ilyastrab
ilyastrab 🇺🇸

4.4

(52)

379 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 1301 – Lab #8
Exercise
The purpose of this exercise is to apply your knowledge about assignments statements,
arithmetic expressions and conditional statements discussed during the lectures.
In this lab exercise, you will enhance the functionality of the java application you
implemented in Lab #4. Your java application will, as before, compute the Body Mass
Index (BMI) according to a person's weight and height but it will also perform input
validation and determine the weight category of the user. For this exercise, modify the
main method of the class BMI you wrote in Lab #4 to do the following:
a)
The program should prompt the user for his/her weight in kilograms, if the user
enters a number less than zero the program will display a message and terminate.
b)
Afterwards, the program should prompt the user for his/her height in meters, if the
user enters a number less than zero, the program will display a message and
terminate.
c)
Then the program will compute the BMI of the user as:
)(
.)(
2
metersheight
kgsweight
BMI =
d)
After computing the user’s BMI score, the program will display:
The user’s weight in both kilograms and pounds
The user’s height in meters as well as in feet and inches
The user’s BMI score and the user’s weight category according to the
following table:
BMI Score Weight Category
Less than 18.5 Underweight
Greater than or equal to 18.5 and less than 25 Normal
Greater than or equal to 25 and less than 30 Overweight
Greater than or equal to 30 Obesity
e)
Additionally, your program will display a disclaimer that states the limitations
of the BMI as follows:
Disclaimer:
The BMI score is valid for both men and women but it does have some limits. The
limits are:
a) It may overestimate body fat in athletes and others who have a muscular build.
b) It may underestimate body fat in older persons and others who have lost muscle
mass.
pf2

Partial preview of the text

Download Lab Exercise for Computing Body Mass Index and Determining Weight Category in Java and more Exercises Computer Science in PDF only on Docsity!

CSCI 1301 – Lab

Exercise

The purpose of this exercise is to apply your knowledge about assignments statements, arithmetic expressions and conditional statements discussed during the lectures.

In this lab exercise, you will enhance the functionality of the java application you implemented in Lab #4. Your java application will, as before, compute the Body Mass Index (BMI) according to a person's weight and height but it will also perform input validation and determine the weight category of the user. For this exercise, modify the main method of the class BMI you wrote in Lab #4 to do the following: a) The program should prompt the user for his/her weight in kilograms, if the user enters a number less than zero the program will display a message and terminate. b) Afterwards, the program should prompt the user for his/her height in meters, if the user enters a number less than zero, the program will display a message and terminate. c) Then the program will compute the BMI of the user as:

height^2 meters

weightkgs BMI =

d) After computing the user’s BMI score, the program will display:

  • The user’s weight in both kilograms and pounds
  • The user’s height in meters as well as in feet and inches
  • The user’s BMI score and the user’s weight category according to the following table:

BMI Score Weight Category Less than 18.5 Underweight Greater than or equal to 18.5 and less than 25 Normal Greater than or equal to 25 and less than 30 Overweight Greater than or equal to 30 Obesity

e) Additionally, your program will display a disclaimer that states the limitations of the BMI as follows:

Disclaimer: The BMI score is valid for both men and women but it does have some limits. The limits are: a) It may overestimate body fat in athletes and others who have a muscular build. b) It may underestimate body fat in older persons and others who have lost muscle mass.

Example #1:

Height in meters:-10. Sorry, -10.2 is not a valid height in meters. Bye.

Example #2:

Height in meters:1. Weight in kgs: -15. Sorry, -15.5 is not a valid weight in kilograms. Bye.

Example #3: Height in meters:1. Weight in kgs:

User’s Information: Weight: 92.0 kgs. (202.4 lbs.) Height: 1.89 m. (6' 2") BMI: 25. Weight group: Overweight (*)

(*) Disclaimer:

The BMI score is valid for both men and women but it does have some limits. The limits are: a) It may overestimate body fat in athletes and others who have a muscular build. b) It may underestimate body fat in older persons and others who have lost muscle mass.

Hints:

  • You should use decision statements to validate the user’s input.
  • You may use the exit method to terminate the execution of the program when the input entered by the user is not valid.
  • Use a multibranch decision statement to determine the weight category of the user.

Compile and run your program.

After you have completed this exercise, demonstrate it to your lab instructor.

WebCT Submission

After you have completed both exercises in this lab, upload the file BMI.java in WebCT and submit it to receive credit.