0% found this document useful (0 votes)
0 views11 pages

App Development Lab

The document outlines exercises for an App Development Lab focused on creating a Native Calculator and a Scientific Calculator in Android Studio. It includes XML layout code for both applications and Java code for their respective MainActivity classes, detailing the implementation of basic arithmetic operations and scientific functions. The submission date for both exercises is set for October 6, 2025.

Uploaded by

ayeshafayyaz393
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views11 pages

App Development Lab

The document outlines exercises for an App Development Lab focused on creating a Native Calculator and a Scientific Calculator in Android Studio. It includes XML layout code for both applications and Java code for their respective MainActivity classes, detailing the implementation of basic arithmetic operations and scientific functions. The submission date for both exercises is set for October 6, 2025.

Uploaded by

ayeshafayyaz393
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COURSE TITLE: APP DEVELOPMENT-LAB

EXERCISE: 3.1 & 3.2


EXERCISE 3.1:
Execute the above exercise of Native Calculator in Android studio and show the exact GUI
output? [2]

CODE:
Code for Activity_main.xml:

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


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link] android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CALCULATOR"
android:textSize="20sp"
android:textStyle="bold"
android:layout_gravity="center"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<EditText
android:id="@+id/editTextText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="Enter no 1"
/>

<EditText

SUBMISSION DATE: 6-OCT-2025


android:id="@+id/editTextText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"
android:hint="Enter no 2"
/> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<Button android:id="@+id/sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />

<Button android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />

<Button android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*" />

<Button android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />

</LinearLayout>

<TextView android:id="@+id/res"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Answer is"
android:textSize="30sp"
/>
</LinearLayout>

Code for [Link]:

SUBMISSION DATE: 6-OCT-2025


package [Link].madlabex31;

import [Link];

import [Link]; import


[Link];
import [Link]; import
[Link]; import
[Link];

import [Link]; import


[Link]; import
[Link]; import
[Link]; import
[Link]; import
[Link]; import
[Link];

import [Link]; import


[Link];
import [Link]; import
[Link]; import
[Link];

public class MainActivity extends AppCompatActivity implements OnClickListener {


EditText input1,input2;
Button addition,subtraction,multiplication,division;

TextView result;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
input1=findViewById([Link]);
input2=findViewById([Link].editTextText2);
addition=findViewById([Link]);
subtraction=findViewById([Link]);
multiplication=findViewById([Link]);
division=findViewById([Link]);
result=findViewById([Link]);

SUBMISSION DATE: 6-OCT-2025


[Link](this);
[Link](this);
[Link](this);
[Link](this);
}
public void onClick(View v){
String number1=[Link]().toString();
String number2=[Link]().toString();
if([Link](number1)||[Link](number2)){
return;
}
Float num1=[Link](number1);
Float num2=[Link](number2);

String operation="";
float finalresult=0;

switch ([Link]()){ case


[Link]: operation="+";
finalresult=num1+num2;
break; case
[Link]: operation="-";
finalresult=num1-num2;
break; case
[Link]: operation="*";
finalresult=num1*num2;
break; case
[Link]: operation="/";
finalresult=num1/num2;
break;
}
[Link](num1+operation+num2+"="+finalresult);
}
}

IN GRADLE PROPERTIESWRITE FOLLOWING COMMAND:

[Link]=false

SUBMISSION DATE: 6-OCT-2025


OUTPUT:

EXERCISE 3.2:

Develop an android application for Scientific Calculator. Mathematical functionality should be present e.g.
Sin, Tan, Cos, Sqrt, log etc.

CODE:
Code for Activity_main.xml:

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


<LinearLayout

SUBMISSION DATE: 6-OCT-2025


xmlns:android="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCIENTIFIC CALCULATOR"
android:textSize="24sp"
android:textStyle="bold"
android:layout_gravity="center"
android:paddingBottom="16dp"
/>

<EditText
android:id="@+id/inputNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter number"
android:inputType="numberDecimal|numberSigned"
android:textSize="18sp"
android:padding="10dp"
/>

<!-- Scientific functions -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp"
android:weightSum="5">

<Button android:id="@+id/btnSin"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="sin"
/>

<Button
android:id="@+id/btnCos"

SUBMISSION DATE: 6-OCT-2025


android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="cos"
/>

<Button
android:id="@+id/btnTan"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="tan"
/>

<Button
android:id="@+id/btnSqrt"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="√"
/>

<Button
android:id="@+id/btnLog"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="log"
/>
</LinearLayout>

<!-- Result display --> <TextView


android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Result: "
android:textSize="24sp"
android:paddingTop="24dp"
android:textAlignment="center"
/>
</LinearLayout>

Code for [Link]:

package [Link].madlabex32;

SUBMISSION DATE: 6-OCT-2025


import [Link]; import [Link]; import [Link];
import [Link]; import [Link]; import
[Link]; import [Link]; public
class MainActivity extends AppCompatActivity implements [Link] {

EditText inputNumber;
Button btnSin, btnCos, btnTan, btnSqrt, btnLog;
TextView result;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

inputNumber = findViewById([Link]);
btnSin = findViewById([Link]);
btnCos = findViewById([Link]);
btnTan = findViewById([Link]);
btnSqrt = findViewById([Link]);
btnLog = findViewById([Link]);
result = findViewById([Link]);

[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
}

@Override
public void onClick(View v) {
String inputStr = [Link]().toString();
if ([Link](inputStr)) {
[Link]("Please enter a number");
return;
}

try {

double

inputVal

SUBMISSION DATE: 6-OCT-2025


Double.

parseDo

uble(inp

utStr);

double output = 0;
String operation = "";

switch ([Link]()) {
case [Link]:
output = [Link]([Link](inputVal));
operation = "sin(" + inputVal + ")";
break;

case [Link]:
output = [Link]([Link](inputVal));
operation = "cos(" + inputVal + ")";
break;

case [Link]:
output = [Link]([Link](inputVal));
operation = "tan(" + inputVal + ")";
break;

case [Link]:
if (inputVal < 0) {
[Link]("Invalid input for sqrt");
return;
}
output = [Link](inputVal);
operation = "√" + inputVal;
break;

case [Link]:
if (inputVal <= 0) {
[Link]("Invalid input for log");
return;
}
output = Math.log10(inputVal);
operation = "log(" + inputVal + ")";
break;
}

SUBMISSION DATE: 6-OCT-2025


[Link](operation + " = " + output);
} catch (NumberFormatException e) {
[Link]("Invalid input");
}
}
}
OUTPUT:

SUBMISSION DATE: 6-OCT-2025


SUBMISSION DATE: 6-OCT-2025

You might also like