Mad MP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Calculator In Android Studio

Mobile Application Development


Microproject

1
Calculator In Android Studio

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MICROPROJECT
Academic Year: 2023-2024

Topic:- Calculator In Android Studio


Program:- Computer Engineering.
Subject Name:- Mobile Application Development
Course code:- 22617

Course:- CO6I

Prof. S.S.Malwade Prof. J.G.Khurpade PROF. DR. R.S.KALE

[Name of Guide] [Name of HOD] [Principal]

2
Calculator In Android Studio

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION


CERTIFICATE

This is to certify that Mr. Roll No: of TYCO of Diploma in Computer


Engineering of Institute: MIT Polytechnic Pune (Code: 0148) has
completed the Micro Project satisfactorily in Subject: Mobile
Application Development For the academic year 2023-2024 as
prescribed in the curriculum.

Place :Pune Enrollment No:

Date: Exam. Seat No: --------

Subject Teacher Head of the Department Principal

(Prof. ) (Prof.) (Prof .)

Institute

Seal
3
Calculator In Android Studio

Index

Sr.No Content Page No.

1. Abstract 8

2. Introduction 9

3. Program 11

4. Output of the project 19

5. Micro-Project Proposal A 20

6. Micro-Project Proposal B 22

7. Conclusion 23

8. Evaluation Sheet 24

4
Calculator In Android Studio

1.0 ABSTSRACT
The calculator app for Android is designed to provide users with a simple yet
effective tool for performing basic mathematical calculations on their mobile
devices. This app is developed using XML for designing the user interface (UI)
and Java for implementing the functionality.

In the XML layout file, various UI components such as buttons, text views, and
layouts are defined to create the visual representation of the calculator. The
layout is designed to be intuitive and user-friendly, with clear labels and
organization to facilitate easy input and output of numerical values and
operations.

The Java code implements the logic for handling user input, performing
calculations, and updating the display accordingly. Event listeners are used to
detect user interactions with the buttons and execute the corresponding actions,
such as appending numbers to the input string, executing arithmetic operations,
clearing the input, and displaying the result.

The calculator app supports basic arithmetic operations including addition,


subtraction, multiplication, and division, as well as functionality for clearing the
input and handling decimal points. Error handling mechanisms are implemented
to ensure the smooth functioning of the app and provide feedback to the user in
case of invalid input or arithmetic errors.

Overall, the calculator app offers a convenient and accessible tool for users to
perform mathematical calculations on their Android devices, enhancing their
productivity and convenience in everyday tasks requiring quick computations.

5
Calculator In Android Studio

2.0 Introduction
In the realm of mobile application development, calculator apps stand as
quintessential tools that cater to fundamental mathematical needs on portable
devices. These apps have evolved from basic arithmetic calculators to
sophisticated tools offering advanced functions, catering to various user
requirements.

The introduction of a calculator app in mobile application development


encapsulates the fusion of simplicity and functionality. It serves as an entry
point for developers to understand and implement core concepts such as user
interface design, event handling, and algorithmic logic within the context of a
practical application.

In essence, the development of a calculator app provides an excellent learning


platform for beginners, while offering opportunities for seasoned developers to
explore optimization techniques and innovative features.

 Key Components of a Calculator App:-


1. User Interface (UI): The UI of a calculator app comprises elements such as
buttons, text fields, and layouts arranged in a visually intuitive manner. Design
considerations include user experience, accessibility, and responsiveness across
different screen sizes and orientations.

2. Functionality: The core functionality of a calculator app involves processing


user input, performing arithmetic operations, and displaying results in real-time.
Error handling, memory functions, and support for advanced mathematical
operations may also be included depending on the app's scope.

3. Event Handling: Event listeners are employed to capture user interactions


with the calculator's UI components, triggering appropriate actions such as
appending digits, executing operations, or clearing the input buffer.

4. Algorithmic Logic: Algorithms for arithmetic operations form the backbone


of a calculator app. Implementations for addition, subtraction, multiplication,
and division should be accurate, efficient, and capable of handling edge cases
and exceptions gracefully.
6
Calculator In Android Studio

5. User Experience (UX): A seamless user experience is paramount for a


successful calculator app. This encompasses factors such as responsiveness,
feedback mechanisms, and visual cues that enhance usability and reduce
cognitive load for the user.

6. Accessibility: Accessibility features ensure that the calculator app is usable


by individuals with disabilities or special needs. Considerations include support
for screen readers, alternative input methods, and high-contrast interfaces.

7. Localization and Internationalization: Supporting multiple languages and


regional conventions enhances the accessibility and usability of the calculator
app for a global audience.

 Creating a simple calculator app for Android:-


Step 1: Create a new Android Studio project. Open Android Studio and create a
new project with an empty activity.

Step 2: Design the layout. Open the "activity_main.xml" file in the "res/layout"
folder.

Step 3: Add the logic in MainActivity.java.

Step 4: Run the app.

A calculator app in mobile application development serves as a fundamental


tool that allows users to perform mathematical calculations on their
smartphones or tablets. This type of app provides a convenient solution for
everyday arithmetic tasks, ranging from simple addition and subtraction to
more complex calculations.

Developing a calculator app offers developers valuable insights into user


interface design, event handling, algorithm implementation, and user
experience optimization. It serves as an accessible entry point for beginners to
learn mobile app development concepts and provides opportunities for
seasoned developers to refine their skills and explore advanced features.

7
Calculator In Android Studio

3.0 Program
.XML Code :-

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout 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"
tools:context=".MainActivity">

<TextView
android:id="@+id/solution_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/result_tv"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/black"
android:textSize="32dp" />

<TextView
android:id="@+id/result_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/buttons_layouts"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="0"
android:textAlignment="textEnd"
android:textColor="@color/black"
android:textSize="64dp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="#EDE7E7"
android:paddingVertical="16dp"
android:id="@+id/buttons_layouts">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">

8
Calculator In Android Studio

<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_c"
android:backgroundTint="#F44336"
android:text="C"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_open_bracket"
android:backgroundTint="#7E7C7C"
android:text="("
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_close_bracket"
android:backgroundTint="#777676"
android:text=")"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_divide"
android:backgroundTint="#FF5722"
android:text="/"
/>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"

9
Calculator In Android Studio

android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_7"
android:text="7"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_8"
android:text="8"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_9"
android:text="9"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_multiply"
android:backgroundTint="#FF5722"
android:text="*"
/>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"

10
Calculator In Android Studio

android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_4"
android:text="4"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_5"
android:text="5"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_6"
android:text="6"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_addition"
android:backgroundTint="#FF5722"
android:text="+"
/>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_1"
android:text="1"
/>

11
Calculator In Android Studio

<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_2"
android:text="2"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_3"
android:text="3"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_substraction"
android:backgroundTint="#FF5722"
android:text="-"
/>

</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="20dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_ac"
android:backgroundTint="#F44336"
android:text="ac"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

12
Calculator In Android Studio

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_0"
android:text="0"
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_dot"
android:text="."
/>
<com.google.android.material.button.MaterialButton
android:layout_width="72dp"
android:layout_height="72dp"
app:cornerRadius="36dp"

style="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"
android:textSize="32dp"
android:textColor="@color/white"
android:layout_margin="12dp"
android:id="@+id/button_equals"
android:backgroundTint="#FF5722"
android:text="="
/>

</LinearLayout>

</LinearLayout>

</RelativeLayout>

.Java Code :-

package com.example.calculator;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.button.MaterialButton;

13
Calculator In Android Studio

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener{

TextView resultTv,solutionTv;
MaterialButton buttonC,buttonBrackOpen,buttonBrackClose;
MaterialButton
buttonDivide,buttonMultiply,buttonPlus,buttonMinus,buttonEquals;
MaterialButton
button0,button1,button2,button3,button4,button5,button6,button7,button8,but
ton9;
MaterialButton buttonac,buttonDot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultTv=findViewById(R.id.result_tv);
solutionTv=findViewById(R.id.solution_tv);

assignId(buttonC,R.id.button_c);
assignId(buttonBrackOpen,R.id.button_open_bracket);
assignId(buttonBrackClose,R.id.button_close_bracket);
assignId(buttonDivide,R.id.button_divide);
assignId(buttonMultiply,R.id.button_multiply);
assignId(buttonPlus,R.id.button_addition);
assignId(buttonMinus,R.id.button_substraction);
assignId(buttonEquals,R.id.button_equals);
assignId(button0,R.id.button_0);
assignId(button1,R.id.button_1);
assignId(button2,R.id.button_2);
assignId(button3,R.id.button_3);
assignId(button4,R.id.button_4);
assignId(button5,R.id.button_5);
assignId(button6,R.id.button_6);
assignId(button7,R.id.button_7);
assignId(button8,R.id.button_8);
assignId(button9,R.id.button_9);
assignId(buttonac,R.id.button_ac);
assignId(buttonDot,R.id.button_dot);

void assignId(MaterialButton btn,int id){


btn=findViewById(id);
btn.setOnClickListener(this);

@Override
public void onClick(View view) {

MaterialButton button=(MaterialButton) view;


String buttonText =button.getText().toString();

14
Calculator In Android Studio

String dataToCalculate = solutionTv.getText().toString();

if(buttonText.equals("ac")){
solutionTv.setText("");
resultTv.setText("0");
return;
}
if(buttonText.equals("=")){
solutionTv.setText(resultTv.getText());
return;
}
if(buttonText.equals("C")){

dataToCalculate=dataToCalculate.substring(0,dataToCalculate.length()-1);
}else{
dataToCalculate=dataToCalculate+buttonText;
}
solutionTv.setText(dataToCalculate);

String finalResult=getResult(dataToCalculate);
if(!finalResult.equals("Err")){
resultTv.setText(finalResult);
}

String getResult(String data){


try{
Context context =Context.enter();
context.setOptimizationLevel(-1);
Scriptable scriptable=context.initStandardObjects();
String
finalResult=context.evaluateString(scriptable,data,"Javascript",1,null).toS
tring();
if(finalResult.endsWith(".0")){
finalResult=finalResult.replace(".0","");
}
return finalResult;
}catch(Exception e){
return "Err";
}

}
}

15
Calculator In Android Studio

4.0 Output of the project :

16
Calculator In Android Studio

Micro-Project Proposal-A
Project Problem Statement/title:- Calculator in Android Studio
1.0 Brief Introduction: A calculator app in mobile application
development serves as a fundamental tool that allows users to perform
mathematical calculations on their smartphones or tablets. This type of app
provides a convenient solution for everyday arithmetic tasks, ranging from
simple addition and subtraction to more complex calculations.

2.0 Aim of the Micro-Project : The aim of a calculator app in mobile


application development is to provide users with a convenient and efficient tool
for performing basic mathematical calculations on their smartphones or tablets,
enhancing productivity and convenience in everyday tasks requiring quick
computations. It aims to offer a user-friendly interface, accurate arithmetic
operations, and seamless functionality across various mobile platforms.
3.0 Action Plan:--
Sr Details of activity Planned Time Name of
No
Start Responsible team
.
Date
member

1. Finalising the Topic 1/02/24 05 pm -06


and Allotment of pm
Work.
2. Searching 05/02/24 06 pm – Verified by All
Information. 08 pm

3. Arranging the 06/02/24 05 pm –


collected information. 06 pm

4. Proofreading the 17/02/24 07 pm –


Information. 08 pm

5. Surveying 18/02/24 05 pm -06


Information pm

6. Requiremen 29/02/24 06 pm –
t Analysis 08 pm

7. Finalizing Layout 25/03/24 05 pm –


06 pm
17
Calculator In Android Studio

8. Generating 26/03/24 07 pm –
Program and Final 08 pm
Execution

9. Report Generation 26/03/24 05 pm –


06 pm
10. Final submission 30/03/24 07 pm – 08 Verified by All &Submitted
pm

4.0 Resources required :-

Sr.No Name of Specification Quantity Remark


. Resources/ma
terial
1. Computer System 12 GB RAM, 1
Windows 11
OS
2. Software Android Studio

3. Other resources internet

Micro-Project Proposal-B

18
Calculator In Android Studio

❖ Project Problem Statement/title:- Calculator in Android Studio

1.0 Course outcome : In the realm of mobile application development,


calculator apps stand as quintessential tools that cater to fundamental
mathematical needs on portable devices. These apps have evolved from basic
arithmetic calculators to sophisticated tools offering advanced functions,
catering to various user requirements.

2.0 Brief Introduction : The introduction of a calculator app in mobile


application development encapsulates the fusion of simplicity and functionality.
It serves as an entry point for developers to understand and implement core
concepts such as user interface design, event handling, and algorithmic logic
within the context of a practical application.

3.0 Aim of the Micro-Project: The aim of a calculator app in mobile


application development is to provide users with a convenient and efficient tool
for performing basic mathematical calculations on their smartphones or tablets,
enhancing productivity and convenience in everyday tasks requiring quick
computations.
.
4.0
Actual Resources used : Android Studio

5.0 Skill Developed/learning out of this Micro-Project:

1. Android App Learning


2. UI/UX Design
3. Event Handing
4. Arithmetic Operations
5. Error Handing

6.0 CONCLUSION :-

The development of a calculator app serves as a foundational exercise in mobile


application development, offering insights into various aspects of software
design, implementation, and testing. It provides developers with a practical
19
Calculator In Android Studio

context to apply theoretical concepts, experiment with different techniques, and


iterate towards a polished end product.

As mobile technology continues to advance, the evolution of calculator apps


reflects the ongoing quest to balance simplicity with sophistication, catering to
the diverse needs and preferences of users worldwide.

In conclusion, the calculator app in mobile application development represents a


foundational tool that seamlessly integrates simplicity and functionality. It
serves as an accessible platform for users to perform basic mathematical
operations with ease, while offering developers valuable insights into UI/UX
design, event handling, and algorithm implementation. With its practical utility
and intuitive interface, the calculator app remains a cornerstone of mobile
technology, exemplifying the marriage of convenience and innovation in
modern app development.

Micro-project evaluation sheet

20
Calculator In Android Studio

Rol Student Enroll Process Product Total


l Name m ent Assessme Assessment Mark
no. number nt s
(10)
Part A- Project Part Individual
Project Methodol B-Project Presentation
Propaso ogy report/ /Viva
al (2) working (4)
(2) model
(2)

Comments about team work/leadership/inter-personal


communication (if any):
________________________________________________________________
____________________________________________________

Any Other Comment:


________________________________________________________________
____________________________________________________

Name and designation of the faculty member:


Prof. (Micro-Project Guide)

Signature: ____________________

Logbook of the Student (Weekly Work Report)

21
Calculator In Android Studio

Academic Year: 2023-2024

Name of Students :

Title of the Project:- Calculator in Android Studio

Course : CO6I
Course-code:22617
semester:6I

(Name & Signature of faculty)


Prof.

22

You might also like