Compare commits

..

No commits in common. "a5ef6fcb6642f9685690a3d1d6b5588ccbaa5cb4" and "6fd35a11da9d589c85924e52aa84c61b0a964c46" have entirely different histories.

25 changed files with 311 additions and 595 deletions

144
README.md
View File

@ -1,140 +1,10 @@
# BMI Calculator (UTS Mobile Programming) Kalkulator BMI
===============
## 👨‍💻 Informasi Pengembang
- Dwi Febbryanti (202310715130)
- **F5A5 Mobile Programming**
---
## 📘 Dokumentasi
- Petunjuk detail dapat dibaca di: https://docs.google.com/document/d/1iGiC0Bg3Bdcd2Maq45TYkCDUkZ5Ql51E/edit?rtpof=true
- Starter dimodifikasi dan terinspirasi dari: https://developer.android.com/codelabs/basic-android-compose-calculate-tip#0
---
## 📚 Referensi
- [kotlin.math](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.math/)
- [Calculate the Power of a Number in Kotlin](https://www.baeldung.com/kotlin/power-of-a-number)
- [Centimeters to Inches](https://www.splashlearn.com/math-vocabulary/cm-to-inches)
- [Kilograms to Pound](https://convertlive.com/id/u/mengkonversi/kilo/ke/pound)
- [Unit Testing](https://medium.com/@deonolarewaju/introduction-to-unit-testing-in-android-kotlin-4331eb2366a9)
- [Icon PNG](https://www.flaticon.com/)
---
## 📱 Deskripsi Proyek
Aplikasi BMI Calculator ini merupakan hasil proyek UTS tentang aplikasi berbasis Jetpack Compose yang berfungsi untuk menghitung Body Mass Index (BMI) menggunakan dua standar perhitungan, yaitu SI (kilogram dan sentimeter) serta USC (pound dan inch). Aplikasi ini menyediakan antarmuka yang sederhana dengan fitur input tinggi serta berat badan, pemilihan standar pengukuran melalui switch, serta tombol untuk menghitung dan menghapus data. Hasil perhitungan ditampilkan dalam format satu angka di belakang koma disertai kategori BMI yang relevan, sehingga pengguna dapat mengetahui status berat badan secara cepat dan akurat. Aplikasi ini juga memanfaatkan komponennya secara modular, termasuk fungsi perhitungan BMI, kategori BMI, dan pengaturan tata letak melalui Jetpack Compose.
---
## ✨ Fitur Utama
1. **Perhitungan BMI** dengan dua standar satuan (SI & USC).
2. **Validasi input** berdasarkan rentang nilai tinggi dan berat badan.
3. **Reset otomatis** ketika pengguna beralih standar unit.
4. **Kategori BMI** secara real-time setelah perhitungan.
5. **Antarmuka berbasis Jetpack Compose** dengan tata letak responsif.
6. **Unit Testing** untuk fungsi `calculateBMI()` dan `calculateBMICategory()`.
---
## 🗺️ Cara Menjalankan Aplikasi
### Persyaratan
- Android Studio sudah versi terbaru (Otter)
- Android SDK dan Build Tools untuk menjalankan Compose
- Perangkat Handphone (Debugging) atau Emulator Android
### Langkah Menjalankan
1. Buka Android Studio
2. Pilih Clone Repository ke
https://git.lab.ubharajaya.ac.id/202310715130-DWI-FEBRYANTI/UTS-DwiFebbryanti-202310715130.git
3. Pastikan dependensi Gradle terunduh dan tersinkron
4. Pilih perangkat emulator atau perangkat fisik (Debugging) pada menu Device Manager
5. Tekan Run (Shift +F10) untuk menjalankan aplikasi
6. Aplikasi akan tampil di layar emulator atau perangkat debugging, dan siap digunakan untuk memasukkan tinggi badan, berat badan, dan Standar Perhitungan (SI Metric atau USC Units)
---
## 🧪 Dokumentasi Unit Testing
Pengujian dilakukan pada direktori:
```
app/src/test/java/calculateBMITest
```
Fungsi pengujian:
* `calculateBMITest()`
* `calculateBMICategoryTest()`
### Fokus Pengujian
1. Validasi hasil perhitungan BMI pada unit SI dan USC.
2. Akurasi kategori BMI.
3. Penanganan input tidak valid (tinggi/berat <= 0).
---
## 🔄 Changelog
Changelog disusun berdasarkan riwayat commit/push pada repository.
### v1.4 Penyempurnaan Fitur & Validasi (TERBARU)
* Penyesuaian warna pada tema terang.
* Penambahan validasi input tinggi dan berat.
* Peningkatan UI pada layout untuk konsistensi.
### v1.3 Pembaruan Tampilan & Ikon
* Perubahan ikon aplikasi.
* Optimalisasi tata letak halaman.
* Pembaruan dokumen README.
### v1.2 Integrasi Unit Testing
* Penambahan direktori dan berkas unit test.
* Pengujian ulang fungsi `calculateBMI()` dan `calculateBMICategory()`.
* Penyempurnaan logika pengkategorian BMI.
### v1.1 Penambahan Fitur Pengukuran USC
* Penyesuaian kalkulasi BMI dengan rumus USC.
* Penambahan switch untuk mengganti standar pengukuran.
* Refactor nama fungsi dan variabel.
### v1.0 Rilis Awal
* Implementasi fungsi dasar kalkulasi BMI (SI Unit).
* Struktur awal proyek Jetpack Compose.
* Penambahan komentar proyek (Nama, NPM, Kelas).
---
## 🤝 Kontribusi AI
Pengembangan aplikasi ini turut dibantu oleh:
- **Claude AI**
- **ChatGPT**
Kontribusi yang diberikan:
- Penanganan nilai *NaN → 0*
- Format desimal
- Penerapan rumus BMI sesuai standar SI & USC
- *LaunchedEffect* untuk reset input
- Simplifikasi kondisi kategori BMI
- Penyusunan Unit Testing
- Penyempurnaan layout, penambahan ikon, dan tombol aksi
- Membantu membuat Validasi Input
---
Silahkan kembangkan aplikasi ini untuk melakukan perhitungan BMI
Petunjuk lebih detil dapat dibaca di
https://docs.google.com/document/d/1iGiC0Bg3Bdcd2Maq45TYkCDUkZ5Ql51E/edit?rtpof=true
Starter dimodifikasi dan terinspirasi dari:
https://developer.android.com/codelabs/basic-android-compose-calculate-tip#0

View File

@ -20,9 +20,9 @@
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/bmi_icon" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/bmi_icon_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.TipTime" android:theme="@style/Theme.TipTime"
tools:targetApi="33"> tools:targetApi="33">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

View File

@ -1,393 +1,323 @@
/* /*
* Copyright (C) 2023 The Android Open Source Project * Copyright (C) 2023 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* /*
UTS - BMI Calculator Project UTS - BMI Calculator Project
Nama : Raihan Ariq Muzakki Nama : Raihan Ariq Muzakki
NPM : 202310715297 NPM : 202310715297
Kelas : F5A5 Kelas : F5A5
*/ */
package com.example.bmicalculator package com.example.bmicalculator
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.example.bmicalculator.ui.theme.BMICalculatorTheme import com.example.bmicalculator.ui.theme.BMICalculatorTheme
import java.text.DecimalFormat import java.text.DecimalFormat
import kotlin.math.pow import kotlin.math.pow
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() enableEdgeToEdge()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
BMICalculatorTheme { BMICalculatorTheme {
Surface( Surface(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
) { ) {
BMICalculatorLayout() BMICalculatorLayout()
}
} }
} }
} }
} }
}
// Tata letak Tampilan Aplikasi // Tata letak Tampilan Aplikasi
@Composable @Composable
fun BMICalculatorLayout() { fun BMICalculatorLayout() {
var heightInput by remember { mutableStateOf("") } var heightInput by remember { mutableStateOf("") }
var weightInput by remember { mutableStateOf("") } var weightInput by remember { mutableStateOf("") }
var unitUSC by remember { mutableStateOf(false) } var unitUSC by remember { mutableStateOf(false) }
var errorMessage by remember { mutableStateOf("") }
// State baru untuk mengontrol kapan output ditampilkan // State baru untuk mengontrol kapan output ditampilkan
var showResult by remember { mutableStateOf(false) } var showResult by remember { mutableStateOf(false) }
// Reset nilai input ketika unit berubah // Reset nilai input ketika unit berubah
LaunchedEffect(unitUSC) { LaunchedEffect(unitUSC) {
heightInput = "" heightInput = ""
weightInput = "" weightInput = ""
showResult = false showResult = false
errorMessage = "" }
}
val bmiHeight = heightInput.toDoubleOrNull() ?: 0.0 val bmiHeight = heightInput.toDoubleOrNull() ?: 0.0
val bmiWeight = weightInput.toDoubleOrNull() ?: 0.0 val bmiWeight = weightInput.toDoubleOrNull() ?: 0.0
val bmi = calculateBMI(bmiHeight, bmiWeight, unitUSC) val bmi = calculateBMI(bmiHeight, bmiWeight, unitUSC)
val category = calculateBMICategory(bmi) val category = calculateBMICategory(bmi)
Column( Column(
modifier = Modifier
.statusBarsPadding()
.padding(horizontal = 40.dp)
.verticalScroll(rememberScrollState())
.safeDrawingPadding(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(R.drawable.health_report),
contentDescription = "BMI Icon",
modifier = Modifier modifier = Modifier
.statusBarsPadding() .padding(top = 24.dp, bottom = 16.dp)
.padding(horizontal = 40.dp) .size(80.dp)
.verticalScroll(rememberScrollState()) )
.safeDrawingPadding(),
horizontalAlignment = Alignment.CenterHorizontally Text(
text = stringResource(R.string.calculate_bmi),
style = MaterialTheme.typography.headlineLarge.copy(fontWeight = FontWeight.Bold),
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 32.dp)
)
EditNumberField(
label = if (unitUSC) R.string.heightInch else R.string.heightCm,
leadingIcon = R.drawable.number,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next
),
value = heightInput,
onValueChanged = { heightInput = it },
modifier = Modifier
.padding(bottom = 32.dp)
.fillMaxWidth()
)
EditNumberField(
label = if (unitUSC) R.string.weightPound else R.string.weightKg,
leadingIcon = R.drawable.number,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done
),
value = weightInput,
onValueChanged = { weightInput = it },
modifier = Modifier
.padding(bottom = 32.dp)
.fillMaxWidth()
)
UnitUSCFormulaRow(
unitUSC = unitUSC,
onUSCChanged = { unitUSC = it },
modifier = Modifier.padding(bottom = 24.dp)
)
// Button Kalkulasi dan Clear Field Text
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) { ) {
Image( Button(
painter = painterResource(R.drawable.health_report), onClick = {
contentDescription = "BMI Icon", showResult = true
modifier = Modifier },
.padding(top = 24.dp, bottom = 16.dp) modifier = Modifier.weight(1f)
.size(80.dp) ) {
Text("Calculate")
}
Spacer(modifier = Modifier.width(16.dp))
Button(
onClick = {
heightInput = ""
weightInput = ""
showResult = false
},
modifier = Modifier.weight(1f)
) {
Text("Clear")
}
}
Spacer(modifier = Modifier.height(32.dp))
if (showResult) {
Text(
text = "BMI: $bmi",
style = MaterialTheme.typography.displaySmall,
textAlign = TextAlign.Center,
fontWeight = FontWeight.SemiBold,
modifier = Modifier.fillMaxWidth()
) )
Text( Text(
text = stringResource(R.string.calculate_bmi), text = category,
style = MaterialTheme.typography.headlineLarge.copy(fontWeight = FontWeight.Bold), style = MaterialTheme.typography.displayMedium,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
modifier = Modifier fontWeight = FontWeight.ExtraBold,
.fillMaxWidth() modifier = Modifier.fillMaxWidth()
.padding(bottom = 32.dp)
) )
EditNumberField(
label = if (unitUSC) R.string.heightInch else R.string.heightCm,
leadingIcon = R.drawable.number,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Next
),
value = heightInput,
onValueChanged = { heightInput = it },
modifier = Modifier
.padding(bottom = 32.dp)
.fillMaxWidth()
)
EditNumberField(
label = if (unitUSC) R.string.weightPound else R.string.weightKg,
leadingIcon = R.drawable.number,
keyboardOptions = KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Number,
imeAction = ImeAction.Done
),
value = weightInput,
onValueChanged = { weightInput = it },
modifier = Modifier
.padding(bottom = 32.dp)
.fillMaxWidth()
)
UnitUSCFormulaRow(
unitUSC = unitUSC,
onUSCChanged = { unitUSC = it },
modifier = Modifier.padding(bottom = 24.dp)
)
// Button Kalkulasi dan Clear Field Text
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Button(
onClick = {
// Validasi angka
if (bmiHeight == 0.0 || bmiWeight == 0.0) {
errorMessage = "Input harus berupa angka yang valid."
showResult = false
return@Button
}
// Validasi untuk SI Units
if (!unitUSC) {
if (bmiHeight !in 50.0..300.0 && bmiWeight !in 20.0..500.0) {
errorMessage =
"Masukkan Tinggi Badan pada rentang 50-300 cm \ndan\n Berat Badan pada rentang 20-500 kg"
showResult = false
return@Button
}
else if (bmiHeight !in 50.0..300.0) {
errorMessage = "Tinggi harus berada pada rentang 50300 cm."
showResult = false
return@Button
}
else if (bmiWeight !in 20.0..500.0) {
errorMessage = "Berat harus berada pada rentang 20500 kg."
showResult = false
return@Button
}
}
// Validasi untuk USC Units
if (unitUSC) {
if (bmiHeight !in 20.0..120.0 && bmiWeight !in 44.0..1100.0){
errorMessage =
"Masukkan Tinggi Badan pada rentang 20-120 in dan\n Berat Badan pada rentang 44-110 kg"
showResult = false
return@Button
}
else if (bmiHeight !in 20.0..120.0) {
errorMessage = "Tinggi harus berada pada rentang 20120 in."
showResult = false
return@Button
}
else if (bmiWeight !in 44.0..1100.0) {
errorMessage = "Berat harus berada pada rentang 441100 lbs."
showResult = false
return@Button
}
}
// Jika valid
errorMessage = ""
showResult = true
},
modifier = Modifier.weight(1f)
) {
Text("Calculate")
}
Spacer(modifier = Modifier.width(16.dp))
Button(
onClick = {
heightInput = ""
weightInput = ""
showResult = false
errorMessage = ""
},
modifier = Modifier.weight(1f)
) {
Text("Clear")
}
}
Spacer(modifier = Modifier.height(32.dp))
// Pesan Error
if (errorMessage.isNotEmpty()) {
Text(
text = errorMessage,
color = MaterialTheme.colorScheme.error,
fontWeight = FontWeight.SemiBold,
modifier = Modifier
.padding(top = 16.dp)
.fillMaxWidth(),
textAlign = TextAlign.Center
)
}
Spacer(modifier = Modifier.height(32.dp))
// Output BMI
if (showResult) {
Text(
text = "BMI: $bmi",
style = MaterialTheme.typography.displaySmall,
textAlign = TextAlign.Center,
fontWeight = FontWeight.SemiBold,
modifier = Modifier.fillMaxWidth()
)
Text(
text = category,
style = MaterialTheme.typography.displayMedium,
textAlign = TextAlign.Center,
fontWeight = FontWeight.ExtraBold,
modifier = Modifier.fillMaxWidth()
)
}
Spacer(modifier = Modifier.height(150.dp))
} }
Spacer(modifier = Modifier.height(150.dp))
} }
}
// Fungsi media Input Tinggi Badan dan Berat Badan // Fungsi media Input Tinggi Badan dan Berat Badan
@Composable @Composable
fun EditNumberField( fun EditNumberField(
@StringRes label: Int, @StringRes label: Int,
@DrawableRes leadingIcon: Int, @DrawableRes leadingIcon: Int,
keyboardOptions: KeyboardOptions, keyboardOptions: KeyboardOptions,
value: String, value: String,
onValueChanged: (String) -> Unit, onValueChanged: (String) -> Unit,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) {
TextField(
value = value,
singleLine = true,
leadingIcon = { Icon(painter = painterResource(id = leadingIcon), null) },
modifier = modifier,
onValueChange = onValueChanged,
label = { Text(stringResource(label)) },
keyboardOptions = keyboardOptions
)
}
@Composable
fun UnitUSCFormulaRow(
unitUSC: Boolean,
onUSCChanged: (Boolean) -> Unit,
modifier: Modifier = Modifier
) {
Row(
modifier = modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) { ) {
TextField( Text(text = stringResource(R.string.use_usc), fontWeight = FontWeight.SemiBold)
value = value, Switch(
singleLine = true, modifier = Modifier
leadingIcon = { Icon(painter = painterResource(id = leadingIcon), null) }, .fillMaxWidth()
modifier = modifier, .wrapContentWidth(Alignment.End),
onValueChange = onValueChanged, checked = unitUSC,
label = { Text(stringResource(label)) }, onCheckedChange = onUSCChanged
keyboardOptions = keyboardOptions
) )
} }
}
@Composable /**
fun UnitUSCFormulaRow( * Calculates the BMI
unitUSC: Boolean, * dengan Rumus SI Metrics Unit (Default)
onUSCChanged: (Boolean) -> Unit, * dan
modifier: Modifier = Modifier * dengan Rumus USC Units
) { *
Row( * Catatan: Unit Testing Sudah ada di src/test/java/calculateBMITest.kt
modifier = modifier.fillMaxWidth(), */
verticalAlignment = Alignment.CenterVertically fun calculateBMI(bmiHeight: Double, bmiWeight: Double, unitUSC: Boolean): String {
) { if (bmiHeight <= 0 || bmiWeight <= 0){
Text(text = stringResource(R.string.use_usc), fontWeight = FontWeight.SemiBold) return "0.0"
Switch(
modifier = Modifier
.fillMaxWidth()
.wrapContentWidth(Alignment.End),
checked = unitUSC,
onCheckedChange = onUSCChanged
)
}
} }
/** val heightInMeter = bmiHeight/100 // konversi centimeter ke meter
* Calculates the BMI
* dengan Rumus SI Metrics Unit (Default)
* dan
* dengan Rumus USC Units
*
* Catatan: Unit Testing Sudah ada di src/test/java/calculateBMITest.kt
*/
fun calculateBMI(bmiHeight: Double, bmiWeight: Double, unitUSC: Boolean): String {
if (bmiHeight <= 0 || bmiWeight <= 0){
return "0.0"
}
val heightInMeter = bmiHeight/100 // konversi centimeter ke meter var bmi = bmiWeight / heightInMeter.pow(2)
if (unitUSC) {
var bmi = bmiWeight / heightInMeter.pow(2) bmi = 703 * (bmiWeight / bmiHeight.pow(2))
if (unitUSC) {
bmi = 703 * (bmiWeight / bmiHeight.pow(2))
}
val df = DecimalFormat("#.#")
return df.format(bmi)
} }
/** val df = DecimalFormat("#.#")
* Calculates the BMI Category return df.format(bmi)
* bmi < 18.5 -> Underweight }
* 18.5 <= bmi < 25 -> Normal
* 25 <= bmi <= 30 -> Normal
* bmi > 30 -> Overweight
*
* Catatan: Unit Testing Sudah ada di src/test/java/calculateBMITest.kt
*
*/
fun calculateBMICategory(bmi: String): String {
val bmiValue = bmi.replace(",", ".").toDoubleOrNull() ?: return ""
return when { /**
bmiValue == 0.0 -> "" * Calculates the BMI Category
bmiValue < 18.5 -> "⚠️ Underweight" * bmi < 18.5 -> Underweight
bmiValue < 25.0 -> "✅ Normal" * 18.5 <= bmi < 25 -> Normal
bmiValue < 30.0 -> "⚠️ Overweight" * 25 <= bmi <= 30 -> Normal
else -> "‼️ Obesity" * bmi > 30 -> Overweight
} *
} * Catatan: Unit Testing Sudah ada di src/test/java/calculateBMITest.kt
*
*/
fun calculateBMICategory(bmi: String): String {
val bmiValue = bmi.replace(",", ".").toDoubleOrNull() ?: return ""
@Preview(showBackground = true) return when {
@Composable bmiValue == 0.0 -> ""
fun BMICalculatorLayoutPreview() { bmiValue < 18.5 -> "⚠️ Underweight"
BMICalculatorTheme { bmiValue < 25.0 -> "✅ Normal"
BMICalculatorLayout() bmiValue < 30.0 -> "⚠️ Overweight"
} else -> "‼️ Obesity"
} }
}
@Preview(showBackground = true)
@Composable
fun BMICalculatorLayoutPreview() {
BMICalculatorTheme {
BMICalculatorLayout()
}
}

View File

@ -17,18 +17,18 @@ package com.example.bmicalculator.ui.theme
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
val md_theme_light_primary = Color(0xFF1351AA) // Button val md_theme_light_primary = Color(0xFF984061)
val md_theme_light_onPrimary = Color(0xFFE3E2DE) val md_theme_light_onPrimary = Color(0xFFFFFFFF)
val md_theme_light_primaryContainer = Color(0xFFE3E2DE) val md_theme_light_primaryContainer = Color(0xFFFFD9E2)
val md_theme_light_onPrimaryContainer = Color(0xFF1351AA) val md_theme_light_onPrimaryContainer = Color(0xFF3E001D)
val md_theme_light_secondary = Color(0xFFE3E2DE) val md_theme_light_secondary = Color(0xFF754B9C)
val md_theme_light_onSecondary = Color(0xFF1351AA) val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFE3E2DE) val md_theme_light_secondaryContainer = Color(0xFFF1DBFF)
val md_theme_light_onSecondaryContainer = Color(0xFF1351AA) val md_theme_light_onSecondaryContainer = Color(0xFF2D0050)
val md_theme_light_tertiary = Color(0xFFE3E2DE) val md_theme_light_tertiary = Color(0xFF984060)
val md_theme_light_onTertiary = Color(0xFF1351AA) val md_theme_light_onTertiary = Color(0xFFFFFFFF)
val md_theme_light_tertiaryContainer = Color(0xFFE3E2DE) val md_theme_light_tertiaryContainer = Color(0xFFFFD9E2)
val md_theme_light_onTertiaryContainer = Color(0xFF1351AA) val md_theme_light_onTertiaryContainer = Color(0xFF3E001D)
val md_theme_light_error = Color(0xFFBA1A1A) val md_theme_light_error = Color(0xFFBA1A1A)
val md_theme_light_errorContainer = Color(0xFFFFDAD6) val md_theme_light_errorContainer = Color(0xFFFFDAD6)
val md_theme_light_onError = Color(0xFFFFFFFF) val md_theme_light_onError = Color(0xFFFFFFFF)
@ -38,14 +38,14 @@ val md_theme_light_onBackground = Color(0xFF1351AA)
val md_theme_light_surface = Color(0xFFE3E2DE) val md_theme_light_surface = Color(0xFFE3E2DE)
val md_theme_light_onSurface = Color(0xFF1351AA) val md_theme_light_onSurface = Color(0xFF1351AA)
val md_theme_light_surfaceVariant = Color(0xFFF2DDE2) val md_theme_light_surfaceVariant = Color(0xFFF2DDE2)
val md_theme_light_onSurfaceVariant = Color(0xFF1351AA) val md_theme_light_onSurfaceVariant = Color(0xFF514347)
val md_theme_light_outline = Color(0xFF1351AA) val md_theme_light_outline = Color(0xFF837377)
val md_theme_light_inverseOnSurface = Color(0xFF1351AA) val md_theme_light_inverseOnSurface = Color(0xFFE1F4FF)
val md_theme_light_inverseSurface = Color(0xFF003547) val md_theme_light_inverseSurface = Color(0xFF003547)
val md_theme_light_inversePrimary = Color(0xFF1351AA) val md_theme_light_inversePrimary = Color(0xFFFFB0C8)
val md_theme_light_surfaceTint = Color(0xFF984061) val md_theme_light_surfaceTint = Color(0xFF984061)
val md_theme_light_outlineVariant = Color(0xFFD5C2C6) val md_theme_light_outlineVariant = Color(0xFFD5C2C6)
val md_theme_light_scrim = Color(0xFF1351AA) val md_theme_light_scrim = Color(0xFF000000)
val md_theme_dark_primary = Color(0xFFE3E2DE) val md_theme_dark_primary = Color(0xFFE3E2DE)
val md_theme_dark_onPrimary = Color(0xFF1351AA) val md_theme_dark_onPrimary = Color(0xFF1351AA)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

View File

@ -1,74 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/bmi_icon_background"/>
<foreground android:drawable="@mipmap/bmi_icon_foreground"/>
</adaptive-icon>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/bmi_icon_background"/>
<foreground android:drawable="@mipmap/bmi_icon_foreground"/>
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB