You are on page 1of 8

EX.

NO : 12
DATE :
BMI CALCULATOR
Kavya E , Karunapriya S , Sivapriya P
B.E III year CSE C section

ABSTRACT:
BMI (Body Mass Index) is a number calculated from a person's weight and height. BMI is a fairly
reliable indicator of body fatness for most people. Additionally, BMI is an inexpensive and easy-to-
perform method of screening for weight categories that may lead to health problems. It is a measurement
of a person's leanness or corpulence based on their height and weight, and is intended to quantify tissue
mass. It is widely used as a general indicator of whether a person has a healthy body weight for their
height. Specifically, the value obtained from the calculation of BMI is used to categorize whether a
person is underweight, normal weight, overweight, or obese depending on what range the value falls
between. These ranges of BMI vary based on factors such as region and age, and are sometimes further
divided into subcategories such as severely underweight or very severely obese. Being overweight or
underweight can have significant health effects, so while BMI is an imperfect measure of healthy body
weight, it is a useful indicator of whether any additional testing or action is required.

SOURCE CODE
Activity_main.xml
< RelativeLayout xmlns:android="http://schemasandroid.com/apk/res/android
xmlns:app="http•//schemas.android.com/apk/res-auto'
xmlns:tools="http://schemas.android.com/tools' android:layout_width="match_parent"

tools:context=". MainActivity">

<TextView
android:textStyle="bold" />

<TextView

android:text="Weight(in Kg)"
android:textStyle="bold'
app:layout_constraintBottom_toBottomOf="parent
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf='Þarent"
app:layout_constraintVertical_bias='0292" />

<EditText

<TextView

android:text="Height (in cm)"

android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf='Þarent"
<EditText

android:textSize='20dp" />

<Button

android:backgroundTint="#2CD3BE
android:text="Calculate" />

<TextView
android•id='@+id/bmi_tv"

android:text="The BMI is
android:textSize='20dp"
android:visibility="gone" />

<TextView

android:text="BMl"
android:visibility="gone" />

<TextView

android:textStyle="bold'
android:visibility="gone" />

<Button

android:text="Calculate"/>

</RelativeLayout>
MainActivity.java
package com-example.bmi;

import android.app.Activity;

import android-widget. RadioButton;

import android.widget. RelativeLayout;

import android.widget TextView ;

import android.os. Bundle;

import android.view.View;

import android-widget Toast;


public class MainActivity extends Activity {

private TextView tv 1

privateRelativeLayout rl ;

private RadioButton rbl ,rb2;

@override

protected void onCreate(Bundle savedlnstanceState) {

super.onCreate(savedlnstanceState);

setContentView(R.layout.activity_main);

calculate_btn.setOnClickListener {

if (etHeight.text.isNotEmpty() && etWeight.text.isNotEmpty()) {

val height = (etHeight.text.toString()).tolnt();

val weight = (etWeight.text.toString()).tolnt() ;

val BMI = calculateBMl(height, weight);

bmi.text = BMI.toString();

bmi.visibility = View.VlSlBLE;

if (BMI < 18.5) {


status.text = "Under Weight'’;
} else if (BMI >=18.5 &&BMI < 24.9) {
status.text = "Healthy";
} else if (BMI >=24.9&&BMI < 30) {
status.text = "Overweight";
} else if (BMI>=30) {
status.text = "Suffering from Obesity";

bmi_tv.visibility = View.VISIBLE ;

status.visibility = View.VISIBLE;

Calculate.visibility = View.VISIBLE;
calculate_btn.visibility = View.GONE;

else {
Toast.makeText(this, "please enter the valid height and weight",
;

Calculate.setOnClickListener {
ResetEverything();

}
// Function to reset all Text and EditText fields
private fun ResetEverything() {
calculate_btn.visibility = View.VlSlBLE;
ReCalculate.visibility = View.GONE;

etHeight.text.clear();

etWeight.text.clear();

status.text = bmi.text = " ";

bmi_tv.visibility = View.GONE;

private fun calculateBMl(height: Int, weight: Int): Float {

val Height_in_metre = height.toFloat() / 100;

val BMI = weight.toFloat() / (Height_in_metre * Height_in_metre) ;

return BMI;

}
OUTPUT:

You might also like