- Refactor Nama Package com.example.tiptime menjadi com.example.bmicalculator

- Menambahkan Comment Script untuk Nama dan NPM
- Menyesuaikan nama Fungsi dan Variabel (Unit USC)
This commit is contained in:
202310715297 RAIHAN ARIQ MUZAKKI 2025-11-06 21:06:01 +07:00
parent 099c35f19a
commit c69d20c1b7
6 changed files with 47 additions and 37 deletions

View File

@ -60,7 +60,7 @@ android {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
namespace = "com.example.tiptime"
namespace = "com.example.bmicalculator"
}
dependencies {

View File

@ -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()
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -16,7 +16,7 @@
-->
<resources>
<string name="app_name">BMI Calculator</string>
<string name="calculate_tip">Calculate BMI</string>
<string name="calculate_bmi">Calculate BMI</string>
<string name="height">Tinggi Badan</string>
<string name="weight">Berat Badan</string>
<string name="use_usc">Gunakan Unit USC (lbs/in)?</string>