0% found this document useful (0 votes)
185 views11 pages

CS 4405-01 Mobile Applications - AY2025-T1 WRITTEN ASSIGNMENT UNIT 3

BEST NOTES

Uploaded by

Song Benard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views11 pages

CS 4405-01 Mobile Applications - AY2025-T1 WRITTEN ASSIGNMENT UNIT 3

BEST NOTES

Uploaded by

Song Benard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CS 4405-01 MOBILE APPLICATIONS - AY2025-T1

LEARNING JOURNAL UNIT 3

University of the People

Raval Dipakkumar (Instructor)

SEPTEMBER 23, 2024


Part 1: BMI Calculator App in Kotlin

Introduction

To create a Body Mass Index (BMI) calculator application for the client "123 Start Up," we will

develop an Android application utilizing Kotlin. This application will allow users to enter their

weight, height, and gender, subsequently calculating their BMI to assess whether they fall into the

categories of underweight, normal weight, or overweight. Kotlin programming language. (2021,

November 24).The results will be presented with suitable messages and color coding

corresponding to the BMI value.

Implementation

1. Designing the User Interface

The user interface will include:

 Input Fields: For users to provide their weight, height, and gender.

 Button: To initiate the BMI calculation process.

 TextView: To present the results along with color-coded messages..

2. Kotlin Class for BMI Calculation

We will establish a Person class to manage the input data and perform the BMI calculation.

// Enum class for BMI Categories

enum class BMICategory {


UNDERWEIGHT,

NORMAL,

OVERWEIGHT

// Class to represent a person and calculate BMI

class Person(private val weight: Double, private val height: Double, private val gender: String) {

fun calculateBMI(): Double {

return weight / (height * height)

fun getBMICategory(bmi: Double): BMICategory {

return when {

bmi < 18.5 -> BMICategory.UNDERWEIGHT

bmi in 18.5..24.9 -> BMICategory.NORMAL

else -> BMICategory.OVERWEIGHT

}
}

3. Handling Button Click

Upon the user pressing the calculate button, the application will instantiate the Person class and

present the outcome.

calculateButton.setOnClickListener {

val weight = weightInput.text.toString().toDouble()

val height = heightInput.text.toString().toDouble()

val gender = genderInput.text.toString()

val person = Person(weight, height, gender)

val bmi = person.calculateBMI()

val category = person.getBMICategory(bmi)

resultTextView.text = when (category) {

BMICategory.UNDERWEIGHT -> "You are underweight"

BMICategory.NORMAL -> "Your weight is normal"

BMICategory.OVERWEIGHT -> "You are overweight"

}
resultTextView.setTextColor(

when (category) {

BMICategory.UNDERWEIGHT -> Color.RED

BMICategory.NORMAL -> Color.GREEN

BMICategory.OVERWEIGHT -> Color.RED

(Here is a Screenshots of the App Interface)


Part 2: Simple Calculator App in Kotlin

Introduction

For the straightforward calculator application, we will develop a Kotlin class that executes

fundamental arithmetic operations by employing object-oriented programming principles. Kotlin

- class and objects. (n.d.). This process will incorporate the use of classes, objects, constructors,

and enum classes.

Implementation

1. Establishing the Calculator Class

The Calculator class will encompass properties for the operands and a method to carry out

operations according to an enum class.

package com.example.ucalculator

enum class Operations {

ADD, SUBTRACT, MULTIPLY, DIVIDE

class Calculator(private val operand1: Double, private val operand2: Double) {

fun performOperation(operation: Operations): Double {

return when (operation) {


Operations.ADD -> operand1 + operand2

Operations.SUBTRACT -> operand1 - operand2

Operations.MULTIPLY -> operand1 * operand2

Operations.DIVIDE -> if (operand2 != 0.0) operand1 / operand2 else Double.NaN

2. Using the Calculator Class

This is an example of how the Calculator class can be utilized within your application.

val operand1 = 10.0

val operand2 = 5.0

val operation = Operations.ADD // This could be based on user input

val calculator = Calculator(operand1, operand2)

val result = calculator.performOperation(operation)

resultTextView.text = "Result: $result"


(Here is a Screenshots of the App Interface)
Conclusion

The BMI calculator application exemplifies the application of classes, enums, and object-oriented

programming principles within the Kotlin programming language. Kotlin programming language.

(2021, November 24). Additionally, the straightforward calculator application serves to further

demonstrate the implementation of these concepts in executing fundamental arithmetic operations.

Collectively, both projects underscore the efficacy of Kotlin's object-oriented programming

capabilities in creating functional and user-friendly applications for the Android platform. Kotlin

programming language. (2021, November 24).

677 Words
References

1. GeeksforGeeks. (2021, August 17). Kotlin android tutorial. Retrieved June 23, 2022,

from https://www.geeksforgeeks.org/kotlin-android-tutorial/

2. Kotlin - class and objects. (n.d.).

tutorialspoint. https://www.tutorialspoint.com/kotlin/kotlin_class_and_object.htm

3. Kotlin android tutorial. (2021, January 21). TutorialKart. https://www.tutorialkart.com/kotlin-

android-tutorial/

4. Kotlin object oriented programming concepts. (2021, January 21).

TutorialKart. https://www.tutorialkart.com/kotlin/kotlin-oop/

5. Kotlin OOP. (n.d.). W3Schools.https://www.w3schools.com/kotlin/kotlin_oop.php

6. Kotlin programming language. (2021, November 24). GeeksforGeeks. Retrieved June 23, 2022,

from https://www.geeksforgeeks.org/kotlin-programming-language/

7. lmf. (2020, November 6). Build your first android app in kotlin. Android

Developers. https://developer.android.com/codelabs/build-your-first-android-app-kotlin#0

You might also like