Body Mass Index Write a program that reads names, weights, and heights from bmi.dat (provided with starter code; do not change the file name). Use the information to calculate and displays a person’s body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula: BMI = weight × 703 / height2 where weight is measured in pounds and height is measured in inches. The file is in the format  name weightInKG heightInCM You will read the name, weight and height for 4 people from the file, and you will need to convert the weights in the file to pounds (note that 1 kilogram = 2.2 pounds) and the heights to inches (2.54 cm = 1 inch). The program should display the person's name along with the calculated BMI and a message indicating whether the person has optimal weight, is underweight, or is overweight. Your output should look like    A person’s weight is considered to be optimal if his or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered to be underweight. If the BMI value is greater than 25, the person is considered to be overweight. Input Validation: Make sure all heights and weights read from the file are greater than 0. If a weight or height is read from the file is less than 0 display the following error message "There is a height less than 0. Check the file." and exit the program.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

Body Mass Index

Write a program that reads names, weights, and heights from bmi.dat (provided with starter code; do not change the file name). Use the information to calculate and displays a person’s body mass index (BMI). The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula:

BMI = weight × 703 / height2

where weight is measured in pounds and height is measured in inches.

The file is in the format 

name weightInKG heightInCM

You will read the name, weight and height for 4 people from the file, and you will need to convert the weights in the file to pounds (note that 1 kilogram = 2.2 pounds) and the heights to inches (2.54 cm = 1 inch).

The program should display the person's name along with the calculated BMI and a message indicating whether the person has optimal weight, is underweight, or is overweight.

Your output should look like 

 

A person’s weight is considered to be optimal if his or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered to be underweight. If the BMI value is greater than 25, the person is considered to be overweight.

Input Validation: Make sure all heights and weights read from the file are greater than 0. If a weight or height is read from the file is less than 0 display the following error message "There is a height less than 0. Check the file." and exit the program.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning