Calculator Android Application: Jyoti Tiwari
Calculator Android Application: Jyoti Tiwari
BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY
Submitted By:
Jyoti Tiwari
Roll No: 18362
Submitted To:
Er. Praveen Mishra
HOD (IT)
Signature of Candidate
(Jyoti Tiwari)
ACKNOWLEDGMENT
I am highly grateful to the Er. Praveen Mishra, HOD IT, Institute of Engineering and
Technology, Dr. RML Avadh University, Faizabad, for providing this opportunity to carry out
the Winter Training On Android Application with KOTLIN.
I would like to expresses my gratitude to other faculty members of Information Technology
department of IET, Dr. RML Avadh University, Faizabad, for providing academic inputs,
guidance & encouragement throughout this period.
The author would like to express a deep sense of gratitude and thank Dr.
Rama Pati Mishra Director of the institute, without whose permission, wise counsel and able
guidance, it would have not been possible to carry out my project in this manner.
The help rendered by Mr. Vishal Bhatt, Supervisor for Project is greatly acknowledged.
Finally, I express my indebtedness to all who have directly or indirectly contributed to the successful
completion of my project.
Jyoti Tiwari
CERTIFICATE
I hereby certify that Jyoti Tiwari Roll No. 18362 student of Institute of Engineering and
Technology, Dr. RML Avadh University, Faizabad, has undergone Mini Project from Feburary
to March at our organization to fulfill the requirements for the award of degree of B.Tech.(IT
Branch). She worked on Calculator project during this period under the supervision of Er.
Praveen Mishra (HOD Of Information Technology) During his tenure with us we found him
sincere and hard working. We wish him a great success in the future.
What is Kotlin?
Kotlin tutorial provides basic and advanced concepts of Kotlin programming language. Our
Kotlin tutorial is designed for beginners and professionals both.
Kotlin is a statically-typed, general-purpose programming language. It is widely used to develop
android applications.Kotlin is a general-purpose, statically typed, and open-source programming
language. It runs on JVM and can be used anywhere Java is used today. It can be used to develop
Android apps, server-side apps and much more.
Characteristic of Kotlin
Concise: Kotlin reduces writing the extra codes. This makes Kotlin more concise.
Null safety: Kotlin is null safety language. Kotlin aimed to eliminate the NullPointerException
(null reference) from the code.Interoperable.
Interoperable: Kotlin easily calls the Java code in a natural way as well as Kotlin code can be
used by Java.
Smart cast: It explicitly typecasts the immutable values and inserts the value in its safe cast
automatically.
Tool-friendly: Kotlin programs are build using the command line as well as any of Java IDE.
Extension function: Kotlin supports extension functions and extension properties which
means it helps to extend the functionality of classes without touching their code.
Uses of Kotlin:
Kotlin is an Android-compatible language that is concise, expressive, and designed to be type-
and null-safe. It works with the Java language seamlessly, so it makes it easy for developers who
love the Java language to keep using it but also incrementally add Kotlin code and leverage
Kotlin libraries.
Applications of Kotlin:
Here are the 14 Android Apps that are made using Kotlin for Android.
Pinterest
Postmates
Evernote
Corda
Coursera
Uber
Shadowsocks
Variable in Kotlin
Variable refers to a memory location. It is used to store data. The data of variable can be changed
and reused depending on condition or on information passed to the program.All variables in PHP
are denoted with a leading dollar sign ($).
Variable Declaration
Kotlin variable is declared using keyword var and val.
var (Mutable variable): We can change the value of variable declared using var keyword later
in the program.
val (Immutable variable): We cannot change the value of variable which is declared using val
keyword.
Data types in Kotlin
Data type (basic type) refers to type and size of data associated with variables and functions.
Data type is used for declaration of memory location of variable which determines the features of
data.
In Kotlin, everything is an object, which means we can call member function and properties on
any variable.
Kotlin built in data type are categorized as following different categories:
Number
Character
Boolean
Array
String
Number types of data are those which hold only number type data variables. It is further
categorized into different Integer and Floating point.
Array:Arrays in Kotlin are represented by the Array class. Arrays are created using library
function arrayOf() and Array() constructor. Array has get (), set() function, size property as well
as some other useful member functions.
Creating Array using library function arrayOf()
The arrayOf() function creates array of wrapper types. The item value are passed inside
arrayOf() function like arrayOf(1,2,3) which creates an array[1,2,3].
The elements of array are accessed through their index values (array[index]). Array index are
start from zero.
String:
String in Kotlin is represented by String class. String is immutable, which means we cannot
change the elements in String.
Types of String
String are categorize into two types.
These are:
1. Escaped String: Escape String is declared within double quote (" ") and may contain escape
characters like '\n', '\t', '\b' etc.
2. Raw String: Row String is declared within triple quote (""" """). It provides facility to
declare String in new lines and contain multiple lines. Row String cannot contain any escape
character.
The list of helper functions used for numeric conversion in Kotlin is given below:
• toByte()
• toShort()
• toInt()
• toLong()
• toFloat()
• toDouble()
• toChar()
Kotlin Operator
Operators are special characters which perform operation on operands (values or variable).There
are various kind of operators available in Kotlin.
• Arithmetic operator
• Relation operator
• Assignment operator
• Unary operator
• Bitwise operation
• Logical operator
• Arithmetic Operator
Arithmetic operators are used to perform basic mathematical operations such as addition (+),
subtraction (-), multiplication (*), division (/) etc.
Relation Operator:
Relation operator shows the relation and compares between operands. Following are the different
relational operators:
Assignment operator
Assignment operator "=" is used to assign a value to another variable. The assignment of value
takes from right to left.
Unary Operator
Unary operator is used with only single operand. Following are some unary operator given
below.
Logical Operator
Logical operators are used to check conditions between operands. List of logical operators are
given below.
Bitwise Operation
In Kotlin, there is not any special bitwise operator. Bitwise operation is done using named
function.
Named Function Description Expression
• shl (bits) signed shift left a.shl(b)
• shr (bits) signed shift right a.shr(b)
• ushr (bits) unsigned shift right a.ushr(b)
• and (bits) bitwise and a.and(b)
• or (bits) bitwise or a.or(b)
• xor (bits) bitwise xor a.xor(b)
• inv() bitwise inverse a.inv()
Kotlin Output
Kotlin output operation is performed using the standard methods print() and println().
print(): print() method is used to print values provided inside the method "()"
.
println(): println() method is used to print values provided inside the method "()" and moves
cursor to the beginning of next line.
Kotlin Input
Kotlin has standard library function readLine() which is used for reads line of string input from
standard input stream. It returns the line read or null.
Kotlin Comment
Comments are the statements that are used for documentation purpose. Comments are ignored by
compiler so that don't execute. We can also used it for providing information about the line of
code. There are two types of comments in Kotlin.
Kotlin if Expression
In Kotlin, if is an expression is which returns a value. It is used for control the flow of program
structure.
There is various type of if expression in Kotlin.
• if-else expression
• if-else if-else ladder expression
• nested if expression
Traditional if Statement
Syntax of traditional if statement
if(condation){
//code statement
}
var number = 4
when(number) {
1 -> println("One")
2 -> println("Two")
3 -> println("Three")
4 -> println("Four")
5 -> println("Five")
else -> println("invalid number")
}
For Example:
If the body of for loop contains only one single line of statement, it is not necessary to enclose
within curly braces {}.
Syntax
while(condition){
//body of loop
}
For example:
As a do block of do-while loop executed first before checking the condition, do-while loop
execute at least once even the condition within while is false. The while statement of do-while
loop end with ";" (semicolon).
Syntax:
do{
//body of do block
}
while(condition);
Example of do -while loop
In this example do-while loop execute at once time even the condition of while is false.
Break Expression
A break expression is used for terminate the nearest enclosing loop. It is almost used with if-else
condition.
For Example:
fun main(args: Array<String>) {
for (i in 1..5) {
if (i == 3) {
break
}
println(i)
}
}
In the above example, when the value of i became equal to 3 and satisfy the if condition(i==3)
than the break expression execute and terminate for loop.
Labeled is the form of identifier followed by the @ sign, for example abc@, test@. To make an
expression as label, we just put a label in front of expression.
Kotlin labeled break expression is used to terminate the specific loop. This is done by using
break expression with @ sign followed by label name (break@loop).
Kotlin labeled break example
For example
fun main(args: Array<String>) {
for (i in 1..3) {
println("i = $i")
if (j == 2) {
continue
}
println("this is below if")
}
}
Kotlin, labeled continue expression is used for repetition of specific loop (labeled loop). This is
done by using continue expression with @ sign followed by label name (continue@labelname).
Kotlin Function
Function is a group of inter related block of code which performs a specific task. Function is
used to break a program into different sub module. It makes reusability of code and makes
program more manageable.
In Kotlin, functions are declared using fun keyword. There are two types of functions depending
on whether it is available in standard library or defined by user.
For example
Here, sqrt() is a library function which returns square root of a number (Double value).
print() library function which prints a message to standard output stream
.
User defined Function:
User defined function is a function which is created by user. User defined function takes the
parameter(s), perform an action and return the result of that action as a value.
Kotlin functions are declared using the fun keyword.
For example:
fun functionName(){
// body of function
}
We have to call the function to run codes inside the body of the function.
functionName()
If a function does not returns any value than its return type is Unit. It is optional to specify the
return type of function definition which does not returns any value.
Syntax:
fun functionName(){
.. .. ..
functionName() //calling same function
}
var count = 0
fun rec(){
count++;
if(count<=5){
println("hello "+count);
rec();
}
}
fun main(args: Array<String>) {
rec();
}
General Recursion
Let's see an example of calculating sum of nth (100000 larger number) using general (normal)
recursion.
Tail Recursion
Tail recursion is a recursion which performs the calculation first, then makes the recursive call.
The result of current step is passed into the next recursive call.
Tail recursion follows one rule for implementation. This rule is as follow:
The recursive call must be the last call of the method. To declare a recursion as tail recursion we
need to use tailrec modifier before the recursive function.
If a function is called without passing any argument than default argument are used as parameter
of function definition. And when a function is called using argument, than the passing argument
is used as parameter in function definition.
Before we will discuss about the named parameter, let's do some modify in the above program.
Named Argument
To solve the above problem a named argument is used.
A named argument is an argument in which we define the name of argument in the function call.
The name defined to argument of function call checks the name in the function definition and
assign to it.
Syntax of lambda:
{ variable -> body_of_function}
Before we talk about lambda, let's see a simple example of addition of two numbers using
normal function.
Learn how to create a scientific calculator app in android studio. This is a good android project
for beginners, as it will increase your ability to apply logic while you’re coding.
What is Android?
Future Scope:
Android is the leading mobile OS in the market. As we know the demand for Android phones is
growing exponentially, the number of Android phone users has grown in abundance over the last
decade. It is running on many devices, not only smartphones but also on tablets television sets,
books, readers, etc.
Due to this exponential growth android has become the hottest technology for technocrats.
Freshers, as well as experienced professionals, are looking forward to boost their profile with this
ever-growing technology.
Project Details
A Scientific Calculator is useful for situations where we need to calculate some complex things
like logs or trigonometry. In such cases, the normal calculator won’t be useful for us. So
therefore, we are here to develop a Scientific Calculator.
• First, it will have a screen to display the user inputs and by default, it will display a “0”.
To make this we will use Text View.
• Then there will be another screen that shows the result and the operator. It will be a
TextView too.
• Then we’ll have the keys, that will have numbers as well as the operators on it. We’ll use
Buttons for this.
• We’ll use a Linear layout for this so that we can arrange the buttons in the desired
manner.
To develop this application there are certain things that you need to know beforehand. So let us
see its requirements and the platform that we’ll use for this project. Let us begin with the tool
that we’ll use for our Scientific Calculator. The latest Version of Android Studio will be chosen
as the Application Development Platform for it. So, you must be fond of Android Studio and
have good hands on it.
Android Studio is the best and most appropriate IDE for Android app development today. But, in
order to work on Android Studio, there are some concepts that you must be fond of. So, you
should have good hands on the following things to work on Android Studio
MainActivity.java: This file manages the working of this system. Main java file is important as
it is the only file that enables the execution of the application.
Resource folder: This folder will have all the resources that are useful for this project.
Following are the list of resource files that are used in our project-
Drawable: It has the layout and designing of the application components.
Colors: It has all the colors that are used in the project.
Style: Here the styling of the text or components is done.
String: This file defines all the strings that are necessary for the project.
activity_main.xml
<TextView
android:id="@+id/input_user"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@drawable/bgcolor2"
android:gravity="center|end"
android:hint="0"
android:maxLength="14"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="50sp" />
<TextView
android:id="@+id/sign_user"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center|end"
android:padding="10dp"
android:textColor="#000000"
android:textColorHint="#000000"
android:background="@drawable/bgcolor"
android:textSize="32sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:orientation="horizontal"
android:weightSum="5">
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="btn_log"
android:text="log"
android:textAllCaps="false"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="btn_ln"
android:text="ln"
android:textAllCaps="false"
android:background="@drawable/background_btn1"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="btn_power"
android:background="@drawable/background_btn1"
android:text="xⁿ"
android:textAllCaps="false"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="btn_root"
android:text="√"
android:background="@drawable/background_btn1"
android:textAllCaps="false"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="btn_factorial"
android:background="@drawable/background_btn1"
android:text="!"
android:textAllCaps="false"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="5">
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:onClick="btn_sin"
android:text="sin"
android:textAllCaps="false"
android:background="@drawable/background_btn1"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="btn_cos"
android:text="cos"
android:textAllCaps="false"
android:textColor="@color/WhiteText"
android:background="@drawable/background_btn1"
android:textSize="30sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:onClick="btn_tan"
android:text="tan"
android:textAllCaps="false"
android:background="@drawable/background_btn1"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="5">
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_7"
android:text="7"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_8"
android:text="8"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_9"
android:text="9"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_add"
android:text="+"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<ImageButton
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_delete"
android:src="@drawable/ic_backspace_black_24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="5">
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_4"
android:text="4"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_5"
android:text="5"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_6"
android:text="6"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_subtract"
android:text="-"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_clear"
android:text="C"
android:textColor="@color/WhiteText"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="5">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4">
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_1"
android:text="1"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_2"
android:text="2"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_3"
android:text="3"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_multiply"
android:text="×"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:background="@drawable/background_btn1" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@drawable/background_btn1"
android:onClick="btn_0"
android:text="0"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn1"
android:onClick="btn_dot"
android:text="."
android:textColor="@color/WhiteText"
android:textSize="32sp" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_divide"
android:text="÷"
android:textColor="@color/WhiteText"
android:textSize="32sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/background_btn2"
android:onClick="btn_equal"
android:text="="
android:textColor="@color/WhiteText"
android:textSize="32sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
MainActivity.java
package com.dataflair.scientificcalc;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
has_Dot = false;
@SuppressLint("SetTextI18n")
public void btn_0(View view) {
user_input.setText(user_input.getText() + "0");
}
@SuppressLint("SetTextI18n")
public void btn_1(View view) {
user_input.setText(user_input.getText() + "1");
}
@SuppressLint("SetTextI18n")
public void btn_2(View view) {
user_input.setText(user_input.getText() + "2");
}
@SuppressLint("SetTextI18n")
public void btn_3(View view) {
user_input.setText(user_input.getText() + "3");
}
@SuppressLint("SetTextI18n")
public void btn_4(View view) {
user_input.setText(user_input.getText() + "4");
}
@SuppressLint("SetTextI18n")
public void btn_5(View view) {
user_input.setText(user_input.getText() + "5");
}
@SuppressLint("SetTextI18n")
public void btn_6(View view) {
user_input.setText(user_input.getText() + "6");
}
@SuppressLint("SetTextI18n")
public void btn_7(View view) {
user_input.setText(user_input.getText() + "7");
}
@SuppressLint("SetTextI18n")
public void btn_8(View view) {
user_input.setText(user_input.getText() + "8");
}
@SuppressLint("SetTextI18n")
public void btn_9(View view) {
user_input.setText(user_input.getText() + "9");
}
@SuppressLint("SetTextI18n")
public void btn_dot(View view) {
if (!has_Dot) {
if (user_input.getText().equals("")) {
user_input.setText("0.");
} else {
user_input.setText(user_input.getText() + ".");
}
has_Dot = true;
}
}
public void btn_add(View view) {
sign = "+";
val_1 = user_input.getText().toString();
user_input.setText(null);
sign_Box.setText("+");
has_Dot = false;
}
@SuppressLint("SetTextI18n")
public void btn_log(View view) {
sign = "log";
user_input.setText(null);
sign_Box.setText("log");
has_Dot = false;
}
@SuppressLint("SetTextI18n")
public void btn_ln(View view) {
sign = "ln";
user_input.setText(null);
sign_Box.setText("ln");
has_Dot = false;
}
@SuppressLint("SetTextI18n")
public void btn_sin(View view) {
sign = "sin";
user_input.setText(null);
has_Dot = false;
sign_Box.setText("sin");
}
@SuppressLint("SetTextI18n")
public void btn_cos(View view) {
sign = "cos";
user_input.setText(null);
has_Dot = false;
sign_Box.setText("cos");
}
@SuppressLint("SetTextI18n")
public void btn_tan(View view) {
sign = "tan";
user_input.setText(null);
has_Dot = false;
sign_Box.setText("tan");
}
@SuppressLint("SetTextI18n")
public void btn_equal(View view) {
if (sign == null) {
sign_Box.setText("Error!");
} else if (user_input.getText().equals("")) {
sign_Box.setText("Error!");
} else if ((sign.equals("+") || sign.equals("-") || sign.equals("*") ||
sign.equals("/")) && val_1.equals("")) {
sign_Box.setText("Error!");
} else {
switch (sign) {
default:
break;
case "log":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble(val_1);
user_input.setText(Math.log10(num1) + "");
sign = null;
sign_Box.setText(null);
break;
case "ln":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble(val_1);
user_input.setText(Math.log(num1) + "");
sign = null;
sign_Box.setText(null);
break;
case "power":
num1 = Double.parseDouble((val_1));
val_2 = user_input.getText().toString();
num2 = Double.parseDouble(val_2);
user_input.setText(Math.pow(num1, num2) + "");
sign = null;
sign_Box.setText(null);
break;
case "root":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble((val_1));
user_input.setText(Math.sqrt(num1) + "");
sign = null;
sign_Box.setText(null);
break;
case "factorial":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble((val_1));
int i = Integer.parseInt(val_1) - 1;
while (i > 0) {
num1 = num1 * i;
i--;
}
user_input.setText(num1 + "");
sign = null;
sign_Box.setText(null);
break;
case "sin":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble((val_1));
user_input.setText(Math.sin(num1) + "");
sign = null;
sign_Box.setText(null);
break;
case "cos":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble((val_1));
user_input.setText(Math.cos(num1) + "");
sign = null;
sign_Box.setText(null);
break;
case "tan":
val_1 = user_input.getText().toString();
num1 = Double.parseDouble((val_1));
user_input.setText(Math.tan(num1) + "");
sign = null;
sign_Box.setText(null);
break;
case "+":
val_2 = user_input.getText().toString();
num1 = Double.parseDouble(val_1);
num2 = Double.parseDouble(val_2);
answer = num1 + num2;
user_input.setText(answer + "");
sign = null;
sign_Box.setText(null);
break;
case "-":
val_2 = user_input.getText().toString();
num1 = Double.parseDouble(val_1);
num2 = Double.parseDouble(val_2);
answer = num1 - num2;
user_input.setText(answer + "");
sign = null;
sign_Box.setText(null);
break;
case "*":
val_2 = user_input.getText().toString();
num1 = Double.parseDouble(val_1);
num2 = Double.parseDouble(val_2);
answer = num1 * num2;
user_input.setText(answer + "");
sign = null;
sign_Box.setText(null);
break;
case "/":
val_2 = user_input.getText().toString();
num1 = Double.parseDouble(val_1);
num2 = Double.parseDouble(val_2);
answer = num1 / num2;
user_input.setText(answer + "");
sign = null;
sign_Box.setText(null);
break;
}
}
}
} else {
user_input.setText(user_input.getText().subSequence(0,
user_input.getText().length() - 1));
}
}
}
user_input.setText(null);
sign_Box.setText(null);
val_1 = null;
val_2 = null;
sign = null;
has_Dot = false;
}
}
SOFTWARE AND HARDWARE REQUIREMENT USED
Software Requirement:
Kotlin (Optional- Either Java or Kotlin will be enough)
eXtensible Markup Language Basics (XML Basics)
Java Programming
Object Oriented Programming Concepts
Windows/Mac/Linux operating system
Android Studio
Hardware Requirement:
External Android for checking progress of application after debugging
Conclusion
The system that has been presented is mainly used in largescale e-learning. In our rapid changing world,
we find it difficult to overcome the learning challenges and possible achievements.
To bridge this gap, the concepts such as e-learning, e- teaching, e-teachers has become the part of
effective education.
REFERENCES