Instructions: Body Mass Index ( BMI) is a measure of health on weigh and can be
ID: 3870780 • Letter: I
Question
Instructions: Body Mass Index ( BMI) is a measure of health on weigh and can be calculated via taking the weight in Kilogram and dividing by square of the height in meters. You are required to write a java program that calculates the BMI via prompting the user to enter both weight in Kilograms and height in centimeters. The program should then calculate and display the weight, height and their associated BMI. Below is a sample output of the program Please enter person weight in Kg 78.5 Please enter person height in Centimeter 165 The BMI for a person with weight of 78.5 Kg and height of 165.0 cm is 28.83 Notes 1. Lab is worth 5% of total mark 2. Submission of the lab is no later than 27h September 2017@ 23:59 3. Any submission via email or after deadline will not be accepted 4. You are required to add comments to your code showing the different aspects 5. Work can be done either individually or a group of no more than two students 6. You are required to submit your soft copy of your java code file via Blackboard 7. Comments will part of the marking 8. Make sure to write your name(s) and IDs when submittingExplanation / Answer
Java code:
import java.util.*;
public class BMICalculatorProgram{
public static void main(String[] args) {
int weight = 0;
int height = 0;
int bmiValue = 0;
try{
System.out.println("Please enter person weight in kg: ");
Scanner key = new Scanner(System.in);
weight = key.nextInt();
System.out.println("Please enter person height in centimeter: ");
height = key.nextInt();
bmiValue = (100*100*weight)/(height*height);
System.out.println("The BMI for a person with weight of" + weight + "and height of" + height + "is" + bmiValue);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Output:
Please enter person weight in kg:
44
Please enter person height in centimeter:
67
The BMI for a person with weight of44and height of67is98