0% found this document useful (0 votes)
146 views26 pages

Written Assignment Unit 3 - CS 4405-01 (Mobile Applications)

ZDFGZGFgZDG

Uploaded by

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

Written Assignment Unit 3 - CS 4405-01 (Mobile Applications)

ZDFGZGFgZDG

Uploaded by

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

Written Assignment Unit 3

Department of Science, University of the People

CS 4405-01: Mobile Applications (Group 0003)

Raval Dipakkumar (Instructor)

September 25th, 2024


Written Assignment Unit 3

Introduction

As a mobile application developer, I was responsible for developing two Android applications

based on unique customer needs. The first application is a BMI calculator, which helps a

corporation track the health of its personnel. The second is a basic calculator that can perform

simple arithmetic operations. Both applications will be built with Kotlin, which uses Object-

Oriented Programming (OOP) concepts to generate structured and reusable code. This paper

describes the procedures I followed to accomplish each section of the assignment, as well as the

important technical concepts employed during the development process.

Part 1: BMI Calculator

In the first part of the assignment, the goal was to create an Android application that calculates

the Body Mass Index (BMI) of a user and classifies them as underweight, normal weight, or

overweight. The app is designed to take inputs from the user, such as weight, height, and gender,

and display the BMI result with appropriate color coding based on the classification.

Steps Taken

1. UI Design: I started by designing the user interface in activity_main.xml. The

layout included EditText fields for the user to input their weight and height, and a
Spinner to allow selection of gender. I also added a "Calculate" button that triggers the

BMI calculation.

2. Business Logic: Next, I created a Kotlin class named Person to represent the user's

details. This class contained properties for weight, height, and gender. I then

implemented a method called calculateBMI() within the Person class, which

calculates BMI using the formula:

BMI = weight / (height * height)

3. Enum Class for BMI Categories: I created an enum class BMICategory to represent

the different BMI classifications: UNDERWEIGHT, NORMAL, and OVERWEIGHT. This

enum class helped categorize the BMI value based on predefined ranges:

enum class BMICategory {

UNDERWEIGHT, NORMAL, OVERWEIGHT

4. Displaying Results: Once the BMI was calculated, I used a when clause to determine

the category the user falls into and displayed the result on a new screen. If the user was

underweight or overweight, the message was displayed in red, while a normal BMI result

was shown in green.

5. Handling User Input: In MainActivity.kt, I added logic to retrieve the user’s

input when the "Calculate" button was clicked. I instantiated the Person class using the
input values and called the calculateBMI() method. The result was then displayed

on the screen, including a message reflecting the user’s BMI category.


Part 2: Basic Calculator

For the second part of the assignment, I developed a simple calculator app that could perform

basic arithmetic operations—addition, subtraction, multiplication, and division—using Kotlin’s

OOP concepts. The app took two numeric inputs and performed the selected operation based on

user choice.

Steps Taken

1. UI Design: I designed a simple interface in activity_main.xml consisting of two

EditText fields to accept the operands and four buttons to represent the four

mathematical operations: addition, subtraction, multiplication, and division.

2. Calculator Class: I created a Calculator class with properties operand1 and

operand2 to store the two input values. A constructor was used to initialize these

properties when an instance of the class was created.

3. Enum Class for Operations: To represent the four operations, I created an enum class

named OperationType. This enum contained cases for ADD, SUBTRACT,

MULTIPLY, and DIVIDE. This allowed me to define the different operations in a

structured way:

enum class OperationType {

ADD, SUBTRACT, MULTIPLY, DIVIDE

}
4. Operation Logic: I implemented a method performOperation() within the

Calculator class that accepted an OperationType as an argument. I used a when

clause to determine which operation to perform based on the selected enum value:

fun performOperation(operation: OperationType): Double {

return when (operation) {

OperationType.ADD -> operand1 + operand2

OperationType.SUBTRACT -> operand1 - operand2

OperationType.MULTIPLY -> operand1 * operand2

OperationType.DIVIDE -> operand1 / operand2

5. Handling Button Clicks: In MainActivity.kt, I added click listeners for each

operation button. When a button was clicked, I retrieved the input values, instantiated the

Calculator class, and called the performOperation() method with the

corresponding operation type. The result of the calculation was then displayed on the

screen
Conclusion

I successfully completed this project by developing two Android applications in Kotlin,

employing essential OOP concepts like classes, objects, constructors, and enum classes. The

BMI calculator helps 123 Start Up employees manage their health, while the basic calculator

illustrates the fundamentals of arithmetic operations in a user-friendly mobile design. Both

applications meet the requirements and provide practical examples of how Kotlin can be used to

create robust, functional Android applications.


References

GeeksForGeeks. (August 30th, 2024). Retrieved from https://www.geeksforgeeks.org/kotlin-


android-tutorial/

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

Traversy Media. (2020, November 10). Build a simple android app with kotlin [Video].
YouTube. https://www.youtube.com/watch?v=BBWyXo-3JGQ

TutorialKart. (n.d). Kotlin Object Oriented Programming Concepts. Retrieved from


https://www.tutorialkart.com/kotlin/kotlin-oop/#google_vignette

TutorialKart. (n.d). Kotlin Android Tutorial. Retrieved from https://www.tutorialkart.com/kotlin-


android-tutorial/#gsc.tab=0

w3schools. (n.d). Kotlin OOP. Retrieved from


https://www.w3schools.com/kotlin/kotlin_oop.php

You might also like