First update calculation
This commit is contained in:
parent
7053fa6573
commit
0ee43c2e9a
@ -81,7 +81,8 @@ fun TipTimeLayout() {
|
||||
|
||||
val BmiHeight = amountInput.toDoubleOrNull() ?: 0.0
|
||||
val BmiWeight = tipInput.toDoubleOrNull() ?: 0.0
|
||||
val tip = calculateBMI(BmiHeight, BmiWeight, roundUp)
|
||||
val bmi = calculateBMI(BmiHeight, BmiWeight, roundUp)
|
||||
val category = calculateBMICategory(BmiHeight, BmiWeight, roundUp)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@ -126,9 +127,14 @@ fun TipTimeLayout() {
|
||||
modifier = Modifier.padding(bottom = 32.dp)
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.bmi_calculation, tip),
|
||||
text = stringResource(R.string.bmi_calculation, bmi),
|
||||
style = MaterialTheme.typography.displaySmall
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.bmi_category, category),
|
||||
style = MaterialTheme.typography.displaySmall
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(150.dp))
|
||||
}
|
||||
}
|
||||
@ -180,13 +186,25 @@ fun RoundTheTipRow(
|
||||
* Catatan: tambahkan unit test untuk kalkulasi BMI ini
|
||||
*/
|
||||
private fun calculateBMI(BmiHeight: Double, BmiWeight: Double = 15.0, roundUp: Boolean): String {
|
||||
var tip = BmiWeight / 100 * BmiHeight
|
||||
var bmi = BmiWeight / 100 * BmiHeight
|
||||
if (roundUp) {
|
||||
tip = kotlin.math.ceil(tip)
|
||||
bmi = kotlin.math.ceil(bmi)
|
||||
}
|
||||
return NumberFormat.getNumberInstance().format(tip)
|
||||
return NumberFormat.getNumberInstance().format(bmi)
|
||||
}
|
||||
/**
|
||||
* Calculates the BMI Category
|
||||
*
|
||||
* 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)
|
||||
}
|
||||
return NumberFormat.getNumberInstance().format(bmi)
|
||||
}
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun TipTimeLayoutPreview() {
|
||||
|
||||
@ -20,6 +20,6 @@
|
||||
<string name="height">Tinggi Badan</string>
|
||||
<string name="weight">Berat Badan</string>
|
||||
<string name="use_usc">Gunakan Unit USC (lbs/in)?</string>
|
||||
<!-- <string name="tip_amount">Tip Amount: %s</string> -->
|
||||
<string name="bmi_calculation">BMI Anda: %s</string>
|
||||
<string name="bmi_category">Kategori: %s</string>
|
||||
</resources>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user