Mad MP
Mad MP
Mad MP
1
Calculator In Android Studio
MICROPROJECT
Academic Year: 2023-2024
Course:- CO6I
2
Calculator In Android Studio
Institute
Seal
3
Calculator In Android Studio
Index
1. Abstract 8
2. Introduction 9
3. Program 11
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.
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.
Step 2: Design the layout. Open the "activity_main.xml" file in the "res/layout"
folder.
7
Calculator In Android Studio
3.0 Program
.XML Code :-
<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;
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);
@Override
public void onClick(View view) {
14
Calculator In Android Studio
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);
}
}
}
15
Calculator In Android Studio
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.
6. Requiremen 29/02/24 06 pm –
t Analysis 08 pm
8. Generating 26/03/24 07 pm –
Program and Final 08 pm
Execution
Micro-Project Proposal-B
18
Calculator In Android Studio
6.0 CONCLUSION :-
20
Calculator In Android Studio
Signature: ____________________
21
Calculator In Android Studio
Name of Students :
Course : CO6I
Course-code:22617
semester:6I
22