Update README.md
This commit is contained in:
parent
0ee43c2e9a
commit
2b98f0256e
@ -5,3 +5,6 @@ Silahkan kembangkan aplikasi ini untuk melakukan perhitungan BMI
|
|||||||
|
|
||||||
Petunjuk lebih detil dapat dibaca di
|
Petunjuk lebih detil dapat dibaca di
|
||||||
https://docs.google.com/document/d/1iGiC0Bg3Bdcd2Maq45TYkCDUkZ5Ql51E/edit?rtpof=true
|
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
|
||||||
@ -127,11 +127,11 @@ fun TipTimeLayout() {
|
|||||||
modifier = Modifier.padding(bottom = 32.dp)
|
modifier = Modifier.padding(bottom = 32.dp)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.bmi_calculation, bmi),
|
text = stringResource(R.string.bmi_calculation, bmi), // rumus
|
||||||
style = MaterialTheme.typography.displaySmall
|
style = MaterialTheme.typography.displaySmall
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.bmi_category, category),
|
text = stringResource(R.string.bmi_category, category), // kategori
|
||||||
style = MaterialTheme.typography.displaySmall
|
style = MaterialTheme.typography.displaySmall
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -185,13 +185,22 @@ fun RoundTheTipRow(
|
|||||||
*
|
*
|
||||||
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||||
*/
|
*/
|
||||||
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double, useUSC: Boolean): String {
|
||||||
var bmi = BmiWeight / 100 * BmiHeight
|
if (BmiHeight <= 0 || BmiWeight <= 0) return "0.0"
|
||||||
if (roundUp) {
|
|
||||||
bmi = kotlin.math.ceil(bmi)
|
val bmi = if (useUSC) {
|
||||||
|
// USC: Berat dalam lbs, tinggi dalam inches
|
||||||
|
703 * (BmiWeight*2.2) / ((BmiHeight*0.29) * (BmiHeight*0.29))
|
||||||
|
} else {
|
||||||
|
// SI Metric: konversi cm ke meter
|
||||||
|
val heightInMeter = BmiHeight / 100
|
||||||
|
BmiWeight / (heightInMeter * heightInMeter)
|
||||||
}
|
}
|
||||||
return NumberFormat.getNumberInstance().format(bmi)
|
|
||||||
|
return String.format("%.2f", bmi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the BMI Category
|
* Calculates the BMI Category
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user