UTS-MUHAMMAD.RAFI
This commit is contained in:
parent
099c35f19a
commit
383da1756f
@ -1,4 +1,4 @@
|
||||
Kalkulator BMI
|
||||
Kalkulator BMI-MUHAMMAD RAFI-202310715191,PENGERJAAN INI DIBANTU AI DALAM MENYEESAIKAN UTS
|
||||
===============
|
||||
|
||||
Silahkan kembangkan aplikasi ini untuk melakukan perhitungan BMI
|
||||
|
||||
@ -185,12 +185,25 @@ fun RoundTheTipRow(
|
||||
*
|
||||
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||
*/
|
||||
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
||||
var bmi = BmiWeight / 100 * BmiHeight
|
||||
if (roundUp) {
|
||||
bmi = kotlin.math.ceil(bmi)
|
||||
//private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
||||
// var bmi = BmiWeight / 100 * BmiHeight
|
||||
// if (roundUp) {
|
||||
// bmi = kotlin.math.ceil(bmi)
|
||||
// }
|
||||
// return NumberFormat.getNumberInstance().format(bmi)
|
||||
//}
|
||||
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double, useUSC: Boolean): String {
|
||||
if (BmiHeight <= 0 || BmiWeight <= 0) return "0.0"
|
||||
|
||||
val bmi = if (useUSC) {
|
||||
// Rumus USC: 703 * weight(lb) / height(in)^2
|
||||
703 * BmiWeight / (BmiHeight * BmiHeight)
|
||||
} else {
|
||||
// Rumus SI: weight(kg) / (height(m))^2
|
||||
BmiWeight / ((BmiHeight / 100) * (BmiHeight / 100))
|
||||
}
|
||||
return NumberFormat.getNumberInstance().format(bmi)
|
||||
|
||||
return String.format("%.2f", bmi)
|
||||
}
|
||||
/**
|
||||
* Calculates the BMI Category
|
||||
@ -198,13 +211,33 @@ private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: B
|
||||
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||
*/
|
||||
|
||||
private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
||||
var bmi = BmiWeight / 100 * BmiHeight
|
||||
if (roundUp) {
|
||||
bmi = kotlin.math.ceil(bmi)
|
||||
//private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
||||
// var bmi = BmiWeight / 100 * BmiHeight
|
||||
// if (roundUp) {
|
||||
// bmi = kotlin.math.ceil(bmi)
|
||||
// }
|
||||
// return NumberFormat.getNumberInstance().format(bmi)
|
||||
//}
|
||||
/**
|
||||
* Menentukan kategori BMI berdasarkan nilai BMI
|
||||
*/
|
||||
private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double, useUSC: Boolean): String {
|
||||
if (BmiHeight <= 0 || BmiWeight <= 0) return "Input tidak valid"
|
||||
|
||||
val bmiValue = if (useUSC) {
|
||||
703 * BmiWeight / (BmiHeight * BmiHeight)
|
||||
} else {
|
||||
BmiWeight / ((BmiHeight / 100) * (BmiHeight / 100))
|
||||
}
|
||||
|
||||
return when {
|
||||
bmiValue < 18.5 -> "Underweight"
|
||||
bmiValue < 25 -> "Normal"
|
||||
bmiValue < 30 -> "Overweight"
|
||||
else -> "Obesity"
|
||||
}
|
||||
return NumberFormat.getNumberInstance().format(bmi)
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun TipTimeLayoutPreview() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user