BMI (Body Mass Index) Calculator using Java Program

Code:

import java.util.Scanner;

public class BMI
{
double weight,feet,inch;

public BMI(double w,double f,double i)
{
weight = w;
feet = f;
inch = i;
}

public double height()
{
return (feet*0.3048)+(inch*0.0254);
}

public double bmi()
{
return Math.round((weight/(height()*height()))*100)/100.0;
}

public String bodytype()
{
              double b = bmi();

              if(b<18.5)
                 return "Underweight";
else if(b>=18.5 && b<=24.9)
return "Normal";
else if(b>=25 && b<=29.9)
return "Overweight";
else if(b==30)
                 return "Obese";
                 return "Obese";
}

public String display()
{
return "\nBMI : "+bmi()+"\tBody Type : "+bodytype()+"\n";
}

        public static void main(String[] args)
        {
Scanner sc = new Scanner(System.in);

System.out.print("\nEnter The Weight In K.G : ");
double w = sc.nextDouble();

System.out.println("\nEnter The Height");

System.out.print("\nFeet : ");
double f = sc.nextDouble();

System.out.print("\nInch : ");
double i = sc.nextDouble();

BMI a = new BMI(w,f,i);

System.out.println(a.display());
         }
}

Output of program:


4 comments:

Powered by Blogger.