A simple calculator application developed using Android Studio. This project demonstrates the implementation of basic arithmetic operations in an Android app, featuring a user-friendly interface and efficient Kotlin code.
- Basic arithmetic operations: addition, subtraction, multiplication, and division.
- Clear and backspace functionalities.
- Responsive user interface compatible with various screen sizes.
- Efficient Kotlin implementation for core functionalities.
This file contains the main activity code, initializing the user interface and handling user interactions.
package com.example.calculadora
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Set up button click listeners
// Example for the number button
button_one.setOnClickListener { appendOnExpression("1", true) }
// More button setup and event listeners...
}
private fun appendOnExpression(string: String, canClear: Boolean) {
// Append text to the expression display
}
}
This file contains the logic for performing arithmetic operations.
package com.example.calculadora
class Calculator {
fun add(a: Double, b: Double): Double {
return a + b
}
fun subtract(a: Double, b: Double): Double {
return a - b
}
fun multiply(a: Double, b: Double): Double {
return a * b
}
fun divide(a: Double, b: Double): Double {
if (b == 0.0) {
throw IllegalArgumentException("Cannot divide by zero")
}
return a / b
}
}
-
Clone the repository:
git clone https://github.com/KPlanisphere/android-calculator.git
-
Open the project in Android Studio.
-
Build and run the application on an emulator or physical device.
- Launch the application on your Android device.
- Use the on-screen buttons to perform arithmetic operations.
- Clear or backspace as needed to correct input.