0% found this document useful (0 votes)
74 views6 pages

Tugas 3: Body Mass Index Calculator

This document describes a mobile application project to calculate Body Mass Index (BMI). It includes screenshots of the Android Studio project and running app. It also includes the XML layout and Java code for the main BMI calculation activity. The XML layout defines the user interface elements like text views, edit texts, and buttons. The Java code calculates BMI based on entered weight and height values, displays the result, and categorizes the BMI into classifications like underweight, normal, overweight, obese etc.

Uploaded by

BasoArfanEfendy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views6 pages

Tugas 3: Body Mass Index Calculator

This document describes a mobile application project to calculate Body Mass Index (BMI). It includes screenshots of the Android Studio project and running app. It also includes the XML layout and Java code for the main BMI calculation activity. The XML layout defines the user interface elements like text views, edit texts, and buttons. The Java code calculates BMI based on entered weight and height values, displays the result, and categorizes the BMI into classifications like underweight, normal, overweight, obese etc.

Uploaded by

BasoArfanEfendy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MATA KULIAH : PRAK.

APLIKASI MOBILE

TUGAS 3
Body Mass Index Calculator

NAMA : BASO ARFAN EFENDY


STB : 172263
KELAS :O
JURUSAN : TEKNIK INFORMATIKA

SEKOLAH TINGGI MENAJEMEN INFORMATIKA DAN KOMPUTER (STMIK)


DIPENAGARA MAKASSAR
2020/2021
Body Mass Index Calculator
 Project Android Studio di Screenshoot tanpa di Crop

 Aplikasi yang telah running di emulator/HP Android di Screenshoot


 Listing XML activity_bmi.xml

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.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"
android:layout_height="match_parent"
tools:context=".BMIActivity">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
android:text="BMI Calculator "
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="Yout BMI"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/BMIResult"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/BMIResult" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="WEIGHT (KG)"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/weightInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/weightInput" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="HEIGHT (M)"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/heightInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/weightInput" />

<TextView
android:id="@+id/BMICategory"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="32dp"
android:gravity="center_horizontal"
android:text="Your BMI category appears here"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView2" />

<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="Calculate my BMI"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/heightInput"
app:layout_constraintTop_toBottomOf="@+id/heightInput" />

<EditText
android:id="@+id/weightInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView1" />

<EditText
android:id="@+id/heightInput"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/weightInput" />

<EditText
android:id="@+id/BMIResult"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:ems="10"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/button3"
app:layout_constraintTop_toBottomOf="@+id/button3" />
</androidx.constraintlayout.widget.ConstraintLayout>

 Listing JAVA BMIActivity.java

package com.prak_basoarfanefendy_172263_o;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.text.DecimalFormat;

public class BMIActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmi);
Button button = (Button)findViewById(R.id.button3);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText heightText = findViewById(R.id.heightInput);
String heightStr = heightText.getText().toString();
double height = Double.parseDouble(heightStr);
final EditText weightText = findViewById(R.id.weightInput);
String weightStr = weightText.getText().toString();
double weight = Double.parseDouble(weightStr);
double BMI = (weight)/(height*height);
DecimalFormat df = new DecimalFormat("#.#");
double BMI_trimmed = Double.parseDouble(df.format(BMI));
final EditText BMIResult = findViewById(R.id.BMIResult);
BMIResult.setText(Double.toString(BMI_trimmed));
String BMI_Cat;
if (BMI < 15)
BMI_Cat = "Very severely underweight";
else if (BMI < 16)
BMI_Cat = "Severely underweight";
else if (BMI < 18.5)
BMI_Cat = "Underweight";
else if (BMI < 25)
BMI_Cat = "Normal";
else if (BMI < 30)
BMI_Cat = "Overweight";
else if (BMI < 35)
BMI_Cat = "Obese Class 1 - Moderately Obese";
else if (BMI < 40)
BMI_Cat = "Obese Class 2 - Severely Obese";
else
BMI_Cat = "Obese Class 3 - Very Severely Obese";
final TextView BMICategory =
findViewById(R.id.BMICategory);
BMICategory.setText(BMI_Cat);
}
});
}
}

You might also like