0% found this document useful (0 votes)
66 views15 pages

Microproject FORMAT MAD

This document describes a project to develop a simple calculator application in Android. It includes the code to build the user interface with buttons and text fields for input/output, and Kotlin code to handle button clicks and perform the basic arithmetic operations of addition, subtraction, multiplication and division on the user input. The prerequisites of Android Studio and related plugins are also listed. The project was completed by three students for their polytechnic course and micro project.

Uploaded by

Gajanan Deutkar
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)
66 views15 pages

Microproject FORMAT MAD

This document describes a project to develop a simple calculator application in Android. It includes the code to build the user interface with buttons and text fields for input/output, and Kotlin code to handle button clicks and perform the basic arithmetic operations of addition, subtraction, multiplication and division on the user input. The prerequisites of Android Studio and related plugins are also listed. The project was completed by three students for their polytechnic course and micro project.

Uploaded by

Gajanan Deutkar
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/ 15

MATSYODARI SHIKSHAN SANSTHA's

College of Engineering & Technology


Campus for Engineering, Polytechnic & MBA

(Polytechnic)

Computer science & Engineering


Department
2021-22
Micro Project
on
“ Develop a Simple Calculator in Android”

Subject :-- MAD(22617)

Submitted by
Roll No Enrollment No Name
CW-04 1915460051 Mujammil Shaikh
CW-05 1915460053 Samihan Ingle
CW-07 1915460055 Gajanan Deutkar

Ms.R.Ingle Ms.R.R.Thombre Prof.Dawane Sir


Subject Guide HOD Incharge
Index

 Introduction
 Prerequisites
 Code
 Output
 References
Introduction

We are going to design a simple functional calculator


application which will perform simple arithmetic operations like
addition , subtraction, multiplication and division. Creating a simple
calculator which can perform basic arithmetic operations like
addition, subtraction, multiplication, or division depending upon the
user input. A sample video is given below to get an idea about
what we are going to do in this article. Note that we are going to
implement this project using the Java language.

Prerequisites

 Android Studio 3.3 or higher


 Kotlin Plugin 1.1.51 or higher
 Java 8 language feature
CODE

XML

<?xml version=”1.0”
encoding=”utf-8”?>
<LinearLayout
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”
Android:padding=”20dp”
Android:orientation=”vertical”
Android:background=”@color/pastel”>

<TextView
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:text=”CALCULATOR”
Android:textSize=”25sp”
Android:layout_marginBottom=”16dp”
Android:textColor=”@android:color/black” />

<LinearLayout
Android:layout_width=”match_parent”
Android:layout_height=”wrap_content”
Android:orientation=”horizontal”
Android:layout_marginBottom=”20dp”>

<EditText
Android:id=”@+id/first_no”
Android:layout_width=”102dp”
Android:layout_height=”59dp”
Android:ems=”10”
Android:layout_marginHorizontal=”50dp”
Android:hint=”Enter” />

<EditText
Android:id=”@+id/second_no”
Android:layout_width=”102dp”
Android:layout_height=”59dp”
Android:ems=”10”
Android:hint=”Enter” />

</LinearLayout>

<LinearLayout
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:orientation=”horizontal”
Android:layout_marginBottom=”20dp”>

<TextView
Android:textSize=”35sp”
Android:id=”@+id/answer”
Android:layout_width=”102dp”
Android:layout_height=”59dp”
Android:layout_marginHorizontal=”50dp”
Android:hint=”ans” />

</LinearLayout>

<LinearLayout
Android:orientation=”vertical”
Android:layout_marginLeft=”250dp”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:layout_marginBottom=”30dp”>

<Button
Android:id=”@+id/sub”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:text=”-“
Android:textSize=”25sp”
Android:layout_marginBottom=”16dp” />
<Button
Android:id=”@+id/add”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:layout_marginBottom=”16dp”
Android:text=”+”
Android:textSize=”25sp”
Tools:ignore=”OnClick” />

<Button
Android:id=”@+id/div”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:text=”/”
Android:textSize=”25sp”
Android:layout_marginBottom=”16dp” />

<Button
Android:id=”@+id/mul”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:layout_marginBottom=”16dp”
Android:text=”X”
Android:textSize=”25sp”/>

<Button
Android:id=”@+id/equals”
Android:layout_width=”wrap_content”
Android:layout_height=”wrap_content”
Android:layout_marginBottom=”16dp”
Android:text=”=”
Android:textSize=”35sp”/>
</LinearLayout>

</LinearLayout>
File: MainActivity.java

JAVA

Package com.example.calculator;

Import
androidx.appcompat.app.AppCompatActivity;

Import android.os.Bundle;
Import android.view.View;
Import android.widget.Button;
Import android.widget.EditText;
Import android.widget.TextView;
Import android.widget.Toast;

Public class MainActivity extends


AppCompatActivity {
EditText no1 , no2;
Button add ,mul ,div , sub,equal;
TextView answer;
Double ans = 0;

@Override
Protected void onCreate(Bundle
savedInstanceState) {
Super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// for text views


No1 = findViewById(R.id.first_no);
No2 = findViewById(R.id.second_no);

// for button with operations


Add = findViewById(R.id.add);
Mul = findViewById(R.id.mul);
Div = findViewById(R.id.div);
Sub = findViewById(R.id.sub);

// for equal to button


Equal = findViewById(R.id.equals);

// for answer field


Answer = findViewById(R.id.answer);

Add.setOnClickListener(new
View.OnClickListener() {
@Override
Public void onClick(View v) {
String num1 =
no1.getText().toString();
String num2 =
no2.getText().toString();

If (num1.isEmpty() ||
num2.isEmpty()) {

Toast.makeText(getApplicationContext(),”Ent
er
Numbers”,Toast.LENGTH_SHORT).show();
}
Else {
Double a =
Double.parseDouble(no1.getText().toString());
Double b =
Double.parseDouble(no2.getText().toString());
Ans = a + b;
}
}
});

Sub.setOnClickListener(new
View.OnClickListener() {
@Override
Public void onClick(View v) {
String num1 =
no1.getText().toString();
String num2 =
no2.getText().toString();

If (num1.isEmpty() ||
num2.isEmpty()) {

Toast.makeText(getApplicationContext(),”Ent
er
Numbers”,Toast.LENGTH_SHORT).show();
}
Else {
Double a =
Double.parseDouble(no1.getText().toString());
Double b =
Double.parseDouble(no2.getText().toString());
Ans = a – b;
}
}
});

Mul.setOnClickListener(new
View.OnClickListener() {
@Override
Public void onClick(View v) {
String num1 =
no1.getText().toString();
String num2 =
no2.getText().toString();

If (num1.isEmpty() ||
num2.isEmpty()) {

Toast.makeText(getApplicationContext(),”Ent
er
Numbers”,Toast.LENGTH_SHORT).show();
}
Else {
Double a =
Double.parseDouble(no1.getText().toString());
Double b =
Double.parseDouble(no2.getText().toString());
Ans = a * b;
}
}
});

div.setOnClickListener(new
View.OnClickListener() {
@Override
Public void onClick(View v) {
String num1 =
no1.getText().toString();
String num2 =
no2.getText().toString();

If (num1.isEmpty() ||
num2.isEmpty()) {

Toast.makeText(getApplicationContext(),
“Enter Numbers”,
Toast.LENGTH_SHORT).show();
} else {
Xx Double a =
Double.parseDouble(no1.getText().toString());
Double b =
Double.parseDouble(no2.getText().toString());
If (b != 0)
Ans = a / b;
Else

Toast.makeText(getApplicationContext(),
“Enter Valid Numbers”,
Toast.LENGTH_SHORT).show();
}
}
});

Equal.setOnClickListener(new
View.OnClickListener() {
@Override
Public void onClick(View v) {
String ans1 = String.valueOf(ans);
Answer.setText(ans1);
Ans= 0;
}
});
}
}

OUTPUT:
References

1. https://medium.com/swlh/simple-calculator-app-in-android-
studio-for-beginners-d0324ef10420

2. https://www.geeksforgeeks.org/how-to-build-a-simple-
calculator-app-using-android-studio/

You might also like