diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f786714..7107dc2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -60,7 +60,7 @@ android { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } - namespace = "com.example.tiptime" + namespace = "com.example.bmicalculator" } dependencies { diff --git a/app/src/main/java/com/example/tiptime/MainActivity.kt b/app/src/main/java/com/example/bmicalculator/MainActivity.kt similarity index 80% rename from app/src/main/java/com/example/tiptime/MainActivity.kt rename to app/src/main/java/com/example/bmicalculator/MainActivity.kt index d0fdd80..46b4ef4 100644 --- a/app/src/main/java/com/example/tiptime/MainActivity.kt +++ b/app/src/main/java/com/example/bmicalculator/MainActivity.kt @@ -13,7 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.example.tiptime + +/* +UTS - BMI Calculator Project +Nama : Raihan Ariq Muzakki +NPM : 202310715297 +Kelas : F5A5 + */ + +package com.example.bmicalculator import android.os.Bundle import androidx.activity.ComponentActivity @@ -54,7 +62,7 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import com.example.tiptime.ui.theme.TipTimeTheme +import com.example.bmicalculator.ui.theme.BMICalculatorTheme import java.text.NumberFormat class MainActivity : ComponentActivity() { @@ -62,27 +70,28 @@ class MainActivity : ComponentActivity() { enableEdgeToEdge() super.onCreate(savedInstanceState) setContent { - TipTimeTheme { + BMICalculatorTheme { Surface( modifier = Modifier.fillMaxSize(), ) { - TipTimeLayout() + BMICalculatorLayout() } } } } } +// Tata letak Tampilan Aplikasi @Composable -fun TipTimeLayout() { - var amountInput by remember { mutableStateOf("") } - var tipInput by remember { mutableStateOf("") } - var roundUp by remember { mutableStateOf(false) } +fun BMICalculatorLayout() { + var heightInput by remember { mutableStateOf("") } + var weightInput by remember { mutableStateOf("") } + var unitUSC by remember { mutableStateOf(false) } - val BmiHeight = amountInput.toDoubleOrNull() ?: 0.0 - val BmiWeight = tipInput.toDoubleOrNull() ?: 0.0 - val bmi = calculateBMI(BmiHeight, BmiWeight, roundUp) - val category = calculateBMICategory(BmiHeight, BmiWeight, roundUp) + val BmiHeight = heightInput.toDoubleOrNull() ?: 0.0 + val BmiWeight = weightInput.toDoubleOrNull() ?: 0.0 + val bmi = calculateBMI(BmiHeight, BmiWeight, unitUSC) + val category = calculateBMICategory(BmiHeight, BmiWeight, unitUSC) Column( modifier = Modifier @@ -94,7 +103,7 @@ fun TipTimeLayout() { verticalArrangement = Arrangement.Center ) { Text( - text = stringResource(R.string.calculate_tip), + text = stringResource(R.string.calculate_bmi), modifier = Modifier .padding(bottom = 16.dp, top = 40.dp) .align(alignment = Alignment.Start) @@ -106,8 +115,8 @@ fun TipTimeLayout() { keyboardType = KeyboardType.Number, imeAction = ImeAction.Next ), - value = amountInput, - onValueChanged = { amountInput = it }, + value = heightInput, + onValueChanged = { heightInput = it }, modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(), ) EditNumberField( @@ -117,13 +126,13 @@ fun TipTimeLayout() { keyboardType = KeyboardType.Number, imeAction = ImeAction.Done ), - value = tipInput, - onValueChanged = { tipInput = it }, + value = weightInput, + onValueChanged = { weightInput = it }, modifier = Modifier.padding(bottom = 32.dp).fillMaxWidth(), ) - RoundTheTipRow( - roundUp = roundUp, - onRoundUpChanged = { roundUp = it }, + UnitUSCFormulaRow( + unitUSC = unitUSC, + onUSCChanged = { unitUSC = it }, modifier = Modifier.padding(bottom = 32.dp) ) Text( @@ -139,6 +148,7 @@ fun TipTimeLayout() { } } +// Fungsi media Input Tinggi Badan dan Berat Badan @Composable fun EditNumberField( @StringRes label: Int, @@ -160,9 +170,9 @@ fun EditNumberField( } @Composable -fun RoundTheTipRow( - roundUp: Boolean, - onRoundUpChanged: (Boolean) -> Unit, +fun UnitUSCFormulaRow( + unitUSC: Boolean, + onUSCChanged: (Boolean) -> Unit, modifier: Modifier = Modifier ) { Row( @@ -174,8 +184,8 @@ fun RoundTheTipRow( modifier = Modifier .fillMaxWidth() .wrapContentWidth(Alignment.End), - checked = roundUp, - onCheckedChange = onRoundUpChanged + checked = unitUSC, + onCheckedChange = onUSCChanged ) } } @@ -185,9 +195,9 @@ fun RoundTheTipRow( * * 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 = 15.0, unitUSC: Boolean): String { var bmi = BmiWeight / 100 * BmiHeight - if (roundUp) { + if (unitUSC) { bmi = kotlin.math.ceil(bmi) } return NumberFormat.getNumberInstance().format(bmi) @@ -198,9 +208,9 @@ 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 { +private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, unitUSC: Boolean): String { var bmi = BmiWeight / 100 * BmiHeight - if (roundUp) { + if (unitUSC) { bmi = kotlin.math.ceil(bmi) } return NumberFormat.getNumberInstance().format(bmi) @@ -208,7 +218,7 @@ private fun calculateBMICategory(BmiHeight: Double, BmiWeight: Double = 15.0, ro @Preview(showBackground = true) @Composable fun TipTimeLayoutPreview() { - TipTimeTheme { - TipTimeLayout() + BMICalculatorTheme { + BMICalculatorLayout() } } \ No newline at end of file diff --git a/app/src/main/java/com/example/tiptime/ui/theme/Color.kt b/app/src/main/java/com/example/bmicalculator/ui/theme/Color.kt similarity index 98% rename from app/src/main/java/com/example/tiptime/ui/theme/Color.kt rename to app/src/main/java/com/example/bmicalculator/ui/theme/Color.kt index bc21042..539c971 100644 --- a/app/src/main/java/com/example/tiptime/ui/theme/Color.kt +++ b/app/src/main/java/com/example/bmicalculator/ui/theme/Color.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.example.tiptime.ui.theme +package com.example.bmicalculator.ui.theme import androidx.compose.ui.graphics.Color diff --git a/app/src/main/java/com/example/tiptime/ui/theme/Theme.kt b/app/src/main/java/com/example/bmicalculator/ui/theme/Theme.kt similarity index 98% rename from app/src/main/java/com/example/tiptime/ui/theme/Theme.kt rename to app/src/main/java/com/example/bmicalculator/ui/theme/Theme.kt index b8c9adb..98eb60a 100644 --- a/app/src/main/java/com/example/tiptime/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/bmicalculator/ui/theme/Theme.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.example.tiptime.ui.theme +package com.example.bmicalculator.ui.theme import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme @@ -90,7 +90,7 @@ private val DarkColorScheme = darkColorScheme( ) @Composable -fun TipTimeTheme( +fun BMICalculatorTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ // Dynamic color in this app is turned off for learning purposes diff --git a/app/src/main/java/com/example/tiptime/ui/theme/Type.kt b/app/src/main/java/com/example/bmicalculator/ui/theme/Type.kt similarity index 96% rename from app/src/main/java/com/example/tiptime/ui/theme/Type.kt rename to app/src/main/java/com/example/bmicalculator/ui/theme/Type.kt index a4cf6e6..9452d07 100644 --- a/app/src/main/java/com/example/tiptime/ui/theme/Type.kt +++ b/app/src/main/java/com/example/bmicalculator/ui/theme/Type.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.example.tiptime.ui.theme +package com.example.bmicalculator.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 04e6db2..d8e8764 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,7 +16,7 @@ --> BMI Calculator - Calculate BMI + Calculate BMI Tinggi Badan Berat Badan Gunakan Unit USC (lbs/in)?