Instructions: Body Mass Index ( BMI) is a measure of health on weigh and can be
ID: 3870073 • 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
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main(String args[]) throws IOException {
float h, w, bmi;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the weight(in kgs):");
w = Float.parseFloat(br.readLine());
System.out.println("enter the height(in meters):");
h = Float.parseFloat(br.readLine());
bmi = (w / (h * h))*10000;
System.out.println("your BMI(body mass index) value is" + bmi);
} catch (NumberFormatException a)
{
System.out.println(a);
}
}
}
output:
enter the weight(in kgs):78.5
enter the height(in meters):165
your BMI(body mass index) value is28.833794