Java Program to Calculate Basal Metabolic Rate

In the previous article, we have seen Java Program to Calculate Body Mass Index

In this article we will see how to calculate Basal Metabolic Rate (BMR) by using Java Programming language.

Java Program to Calculate Basal Metabolic Rate

Before jumping into the program let’s know about Basal Metabolic Rate.

Basal Metabolic Rate:

Basal Metabolic Rate in short BMR which is known as body’s metabolism and it refers to the number of calories required for the body to keep it functioning at rest.

Formula to find BMR:

BMR of Women = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age)

BMR of Men = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age)

Let’s see different ways to find BMR.

Method-1: Java Program to Calculate Basal Metabolic Rate By Using Static Input Value

Approach:

  • Declare gender, weight, height and age value.
  • Check if gender is Male or Female then accordingly find BMR value using formula.
  • Print the result.

Program:

import java.util.Scanner;
 
public class Main
{
    public static void main(String[] args)
    {
        double bmrWomen=0;
        double bmrMen=0;
        
        //Gender 'M' for Male and 'F' for Female
        char gender = 'M';
        
        //weight in lbs
        double weight=125;
         
        //height in inches
        double height = 5.8;
         
        //age in years  
        int age = 21;
        
        if(gender == 'F')
        {
            bmrWomen = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
            System.out.println("BMR for woman: " + bmrWomen);
        }
        else
        {
            bmrMen = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
            System.out.println("BMR for man: " + bmrMen);
        }
    }
}
Output:

BMR for man: 785.52

Method-2: Java Program to Calculate Basal Metabolic Rate By Using User Input Value

Approach:

  • Take gender, weight, height and age value as user input.
  • Check if gender is Male or Female then accordingly find BMR value using formula.
  • Print the result.

Program:

import java.util.Scanner;
 
public class Main
{
    public static void main(String[] args)
    {
        double bmrWomen=0;
        double bmrMen=0;
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        
        System.out.println("Enter your Gender 'M' for Male and 'F' for Female:");
        char gender = sc.next().charAt(0);
        
        System.out.println("Enter weight in lbs:");
        double weight=sc.nextDouble();
         
        System.out.println("Enter height in inches:");
        double height = sc.nextDouble();
         
        System.out.println("Enter age in years:");  
        int age = sc.nextInt();
        
        if(gender == 'F')
        {
            bmrWomen = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
            System.out.println("BMR for woman: " + bmrWomen);
        }
        else
        {
            bmrMen = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
            System.out.println("BMR for man: " + bmrMen);
        }
    }
}
Output:

Enter your Gender 'M' for Male and 'F' for Female:
M
Enter weight in lbs:
118
Enter height in inches:
5.5
Enter age in years:
33
BMR for man: 655.95

Method-3: Java Program to Calculate Basal Metabolic Rate By Using User Defined Method

Approach:

  • Take gender, weight, height and age value as user input.
  • Call a user defined method by passing all these input values as parameter.
  • Inside method check if gender is Male or Female then accordingly find BMR value using formula.
  • Print the result.

Program:

import java.util.Scanner;
 
public class Main
{
    public static void main(String[] args)
    {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        
        System.out.println("Enter your Gender 'M' for Male and 'F' for Female:");
        char gender = sc.next().charAt(0);
        
        System.out.println("Enter weight in lbs:");
        double weight=sc.nextDouble();
         
        System.out.println("Enter height in inches:");
        double height = sc.nextDouble();
         
        System.out.println("Enter age in years:");  
        int age = sc.nextInt();
        
        //calling user defined method findBMR()
        findBMR(gender, weight, height, age);
    }
    
    //findBMR() method to calculate BMR  
    public static void findBMR(char gender, double weight, double height, int age)
    {
        double bmrWomen=0;
        double bmrMen=0;
        
        if(gender == 'F')
        {
            bmrWomen = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
            System.out.println("BMR for woman: " + bmrWomen);
        }
        else
        {
            bmrMen = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
            System.out.println("BMR for man: " + bmrMen);
        }
    }
}
Output:

Enter your Gender 'M' for Male and 'F' for Female:
F
Enter weight in lbs:
118
Enter height in inches:
5.5
Enter age in years:
33
BMR for woman: 1033.15

Guys who are serious about learning the concepts of the java programming language should practice this list of programs in java and get a good grip on it for better results in exams or interviews.

Related Java Programs: