MinorProject AndroidStudioBasedSimpleCalculator January2024Batch Academor
MinorProject AndroidStudioBasedSimpleCalculator January2024Batch Academor
In a world where smartphones are an indispensable part of our lives, having a versatile
calculator on your device can be incredibly convenient. Whether you're a student
tackling complex mathematical problems, a professional in need of quick calculations, or
simply someone looking for a handy tool, our Android calculator app aims to cater to
your needs seamlessly.
Throughout this project, we will explore the fundamentals of Android app development,
leveraging the robust features of Android Studio. From designing a user interface that is
intuitive and visually appealing to implementing the logic that powers the calculator's
functionality, we will delve into the intricacies of creating a reliable and efficient
application.
By the end of this journey, you'll not only have a functional calculator app but also gain
valuable insights into the world of Android development. So, fasten your seatbelts, and
let's embark on this coding adventure to build a simple yet powerful calculator app that
can be a handy companion in your day-to-day life!
METHODOLOGY
The development of the simple calculator using Android Studio involves a systematic and structured
approach to ensure a successful outcome. The methodology comprises several key stages, each
contributing to the overall creation of a functional and user-friendly calculator application.
- Planning the features, user interface, and design elements based on user needs.
2. Environment Setup:
- Installing and set up Android Studio, ensuring that all necessary dependencies are configured.
3. UI Design:
- Designing the user interface of the calculator using XML layout files.
- Implementing an intuitive and visually appealing design that accommodates standard calculator
functionalities.
- Incorporating mechanisms to capture user input from the UI elements (buttons, text fields, etc.).
5. Logic Implementation:
- Developing the core logic for performing basic arithmetic operations (addition, subtraction,
multiplication, division).
- Implementing error handling for invalid input and division by zero scenarios.
- Conducting thorough testing of each component and feature to identify and rectify bugs.
- Testing the app on various Android devices and screen sizes to ensure compatibility.
- Performing user acceptance testing to gather feedback and make necessary adjustments.
- Enhance the app's performance by minimizing resource usage and improving responsiveness during
calculations.
8. Documentation:
- Documenting the code comprehensively, providing comments and explanations for each module.
- Creating a user guide or documentation detailing the app's features, functionality, and usage
instructions.
9. Deployment:
- Distributing the app through appropriate channels, such as the Google Play Store or alternative
distribution platforms.
PROGRAM CODE
Code in the activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8BC34A"
android:backgroundTint="@android:color/darker_gray"
tools:context=".MainActivity">
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="210dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="113dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doSub"
android:text="-"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="307dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doDiv"
android:text="/"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="103dp"
android:layout_height="46dp"
android:layout_marginStart="113dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="206dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMod"
android:text="%(mod)"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.515" />
<Button
android:id="@+id/pow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="113dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="210dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doPow"
android:text="n1^n2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
</androidx.constraintlayout.widget.ConstraintLayout>
Code in the MainActivity.java file
package com.example.calculator2;
import android.os.Bundle;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.example.calculator2.databinding.ActivityMainBinding;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
//checkAndClear();
// defining the edit text 1 to e1
e1 = (EditText) findViewById(R.id.num1);
e2.setText(result);
return false;
}
if((s1.equals(null) && !s2.equals(null))|| (s1.equals("") &&
!s2.equals("")) ){
//checkAndClear();
String result = "Please enter value 1";
e1.setText(result);
return false;
}
if((s1.equals(null) && s2.equals(null))|| (s1.equals("") &&
s2.equals("")) ){
//checkAndClear();
String result1 = "Please enter value 1";
e1.setText(result1);
String result2 = "Please enter value 2";
e2.setText(result2);
return false;
}
else {
// converting string to int.
num1 = Integer.parseInt(s1);
return true;
}
}
public void clearTextNum1(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
double sum = Math.pow(num1, num2);
t1.setText(Double.toString(sum));
}
else
{
t1.setText("Error Please enter Required Values");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.num1);
// defining the edit text 2 to e2
e2 = (EditText) findViewById(R.id.num2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this,
R.id.nav_host_fragment_content_main);
return NavigationUI.navigateUp(navController, appBarConfiguration)
|| super.onSupportNavigateUp();
}
}
RESULTS
As we reflect on the progress made, we've not only achieved our initial goal of building
a functional calculator app but have also gained valuable insights into the principles of
Android app development. From understanding layouts and views to handling user
input and implementing mathematical operations, each step has contributed to our
growing expertise in the field.
Our project has not only equipped us with the technical skills required for Android
development but has also instilled a sense of creativity and problem-solving. We've
witnessed the transformation of lines of code into a tangible, user-friendly application
that can make a meaningful impact in users' daily lives.
As we celebrate the success of this project, let it be a stepping stone for future
endeavors in mobile app development. The knowledge and experience gained here will
undoubtedly serve as a solid foundation for tackling more complex projects and
exploring the ever-expanding possibilities within the realm of technology.
In the dynamic world of software development, this project represents a small yet
significant contribution. We hope our calculator app becomes a practical tool for users
and inspires further curiosity and exploration in the fascinating world of Android app
development. Thank you for joining us on this coding adventure, and may your future
projects be as rewarding and enlightening as this one!