0% found this document useful (0 votes)
5 views

Lakshya Android_lab File

Uploaded by

Lakshya Agarwal
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)
5 views

Lakshya Android_lab File

Uploaded by

Lakshya Agarwal
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/ 20

HALDWANI CAMPUS

PRACTICAL FILE
SUBJECT NAME : ANDROID PROGRAMMING LAB
SUBJECT CODE : PBC 501
COURSE : BCA
SEMESTER : V
SESSION : 2024-25

SUBMITTED TO SUBMITTED BY
Mr. Kamlesh Padaliya Lakshya Agarwal
DEPARTMENT OF COMPUTER SCIENCE
& APPLICATION

COLLEGE ROLL NO. :- 87 EXAMINATION ROLL NO. :- 2292106


HALDWANI CAMPUS

THIS IS TO CERTIFY THAT MR LAKSHYA AGARWAL HAS SATISFACTORILY


COMPLETED ALL THE EXPERIMENTS IN THE LABORATORY OF THIS COLLEGE.
THE COURSE OF THE EXPERIMENTS IN PARTIAL FULLFILLMENT OF THE
REQUIREMENT IN V SEMESTER OF BCA A DEGREE COURSE PRESCRIBED BY
GRAPHIC ERA HILL UNIVERSITY, DEHRADUN DURING THE YEAR 2024-2025

CONCERNED FACULTY HEAD OF DEPARTMENT

NAME OF EXAMINER:
SIGNATURE OF EXAMINER:
DEPARTMENT
STUDENT LAB REPORT SHEET
Android Programming Lab (PBC-501)

Name of Student ……………………………………...……………………………..……. Mo. No…………………….……….…………..

Address Permanent ……………………………………………………………………………………..…………………………..………..

Father’s Name …………………………………..………………………………………… Mo. No…………………………………………

Mother’s Name ……………………………………………………………………………. Mo. No……………………………..…………..

Section ……..……..……. Branch………………………… Semester……….………….. Class Roll No …………………….………..

Local Address……………………………………………………..……Email…………………………………………………..…………..
Grade A B C
Marks 5 3 1
S.No. Name of the Experiment D.O.P. Date of Grade Grade Total Marks Student’s Teacher’s
Submission (Viva) (Report (out of 10) Signature Signature
File)

10

11

12

13

14

15

Total No of Practical allotted ……………………………………….


Total No of Practical completed ……………………………………
Percentage Attendance of Practical ………………………………..
ACKNOWLEDGEMENT

I would like to express my gratitude to Mr. Kamlesh Padaliya for their guidance
and support throughout the completion of this practical file. Their valuable insights
and encouragement have been instrumental in enhancing my understanding of the
subject. Would also like to acknowledge my friends for their collaboration and
help. Thank you all for your contributions to the successful completion of this
practical work.

Lakshya Agarwal
[email protected]
Page No. _1_
PROGRAM NO. 1
NAME :- Lakshya Agarwal
COURSE :- BCA
SEMESTER :- 5th A
ROLL NO. :- 2292106
DATE :- 03/09/2024

OBJECTIVE : Create a basic Hello World program.


PROGRAM:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@android:color/white">

<TextView
android:id="@+id/helloWorldText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
android:textColor="@android:color/black"/>
</LinearLayout>

MainActivity.java
package com.example.helloworldapp;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
OUTPUT:
Page No. _3_
PROGRAM NO. 2
NAME :- Lakshya Agarwal
COURSE :- BCA
SEMESTER :- 5th A
ROLL NO. :- 2292106
DATE :- 10/09/2024

OBJECTIVE : Create a simple application to change colors of background of any


textbox with the click of a button.
PROGRAM:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="16dp">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something"
android:background="#FFC0CB"
android:padding="12dp"
android:textColor="#000000"
android:textSize="18sp"
android:layout_marginBottom="20dp"/>

<Button
android:id="@+id/changeColorButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Color"
android:padding="12dp"
android:textSize="18sp"/>
</LinearLayout>

MainActivity.java
package com.example.changetextboxcolorapp;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

private EditText editText;


private Button changeColorButton;
private Random random;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editText = findViewById(R.id.editText);
changeColorButton = findViewById(R.id.changeColorButton);
random = new Random();

changeColorButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int color = Color.rgb(random.nextInt(256), random.nextInt(256),
random.nextInt(256));
editText.setBackgroundColor(color);
}
});
}
}
OUTPUT:
Page No. _6_
PROGRAM NO. 3
NAME :- Lakshya Agarwal
COURSE :- BCA
SEMESTER :- 5th A
ROLL NO. :- 2292106
DATE :- 17/09/2024

OBJECTIVE : Create a simple application to change background color on button click.


PROGRAM:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="16dp"
android:id="@+id/mainLayout"
android:background="#FFFFFF"> <!-- Set initial background color to white -->

<Button
android:id="@+id/changeColorButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Background Color"
android:padding="12dp"
android:textSize="18sp"/>
</LinearLayout>

MainActivity.java
package com.example.changebackgroundcolorapp;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

private LinearLayout mainLayout;


private Button changeColorButton;
private Random random;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mainLayout = findViewById(R.id.mainLayout);
changeColorButton = findViewById(R.id.changeColorButton);
random = new Random();

changeColorButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int color = Color.rgb(random.nextInt(256), random.nextInt(256),
random.nextInt(256));
mainLayout.setBackgroundColor(color);
}
});
}
}
OUTPUT:
Page No. _9_
PROGRAM NO. 4
NAME :- Varsha Pandey
COURSE :- BCA
SEMESTER :- 5th B
ROLL NO. :- 2292247
DATE :- 24/09/2024

OBJECTIVE : Create a simple application to add two numbers.


PROGRAM:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">

<!-- First Number Input -->


<EditText
android:id="@+id/number1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter first number"
android:inputType="number"
android:textSize="18sp"
android:layout_marginBottom="16dp"/>

<!-- Second Number Input -->


<EditText
android:id="@+id/number2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter second number"
android:inputType="number"
android:textSize="18sp"
android:layout_marginBottom="16dp"/>

<!-- Button to Perform Addition -->


<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
android:textSize="18sp"
android:padding="12dp"/>
<!-- TextView to Display Result -->
<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result will be shown here"
android:textSize="18sp"
android:textColor="#000000"
android:layout_marginTop="20dp"/>
</LinearLayout>

MainActivity.java
package com.example.addtwonumbersapp;

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;

public class MainActivity extends AppCompatActivity {

private EditText number1, number2;


private Button addButton;
private TextView resultTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

number1 = findViewById(R.id.number1);
number2 = findViewById(R.id.number2);
addButton = findViewById(R.id.addButton);
resultTextView = findViewById(R.id.resultTextView);

addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = number1.getText().toString();
String num2 = number2.getText().toString();

if (!num1.isEmpty() && !num2.isEmpty()) {


int result = Integer.parseInt(num1) + Integer.parseInt(num2);

resultTextView.setText("Result: " + result);


} else {
resultTextView.setText("Please enter both numbers");
}
}
});
}
}
OUTPUT:
Page No. _12_
PROGRAM NO. 5
NAME :- Varsha Pandey
COURSE :- BCA
SEMESTER :- 5th B
ROLL NO. :- 2292247
DATE :- 01/10/2024

OBJECTIVE : Create a simple application to create a simple calculator in android.


PROGRAM:

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">

<!-- First Number Input -->


<EditText
android:id="@+id/number1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter first number"
android:inputType="numberDecimal"
android:textSize="18sp"
android:layout_marginBottom="16dp"/>

<!-- Second Number Input -->


<EditText
android:id="@+id/number2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter second number"
android:inputType="numberDecimal"
android:textSize="18sp"
android:layout_marginBottom="16dp"/>

<!-- Buttons for Arithmetic Operations -->


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="20dp">

<!-- Add Button -->


<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:layout_weight="1"/>

<!-- Subtract Button -->


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

<!-- Multiply Button -->


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

<!-- Divide Button -->


<Button
android:id="@+id/divideButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:layout_weight="1"/>
</LinearLayout>

<!-- TextView to Display Result -->


<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result will be shown here"
android:textSize="18sp"
android:textColor="#000000"
android:layout_marginTop="20dp"/>
</LinearLayout>

MainActivity.java
package com.example.simplecalculatorapp;

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;

public class MainActivity extends AppCompatActivity {

private EditText number1, number2;


private Button addButton, subtractButton, multiplyButton, divideButton;
private TextView resultTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

number1 = findViewById(R.id.number1);
number2 = findViewById(R.id.number2);
addButton = findViewById(R.id.addButton);
subtractButton = findViewById(R.id.subtractButton);
multiplyButton = findViewById(R.id.multiplyButton);
divideButton = findViewById(R.id.divideButton);
resultTextView = findViewById(R.id.resultTextView);

addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate('+');
}
});

subtractButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate('-');
}
});

multiplyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate('*');
}
});

divideButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
calculate('/');
}
});
}

private void calculate(char operator) {


String num1Str = number1.getText().toString();
String num2Str = number2.getText().toString();

if (!num1Str.isEmpty() && !num2Str.isEmpty()) {


double num1 = Double.parseDouble(num1Str);
double num2 = Double.parseDouble(num2Str);
double result = 0;

switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
} else {
resultTextView.setText("Cannot divide by zero");
return;
}
break;
}

resultTextView.setText("Result: " + result);


} else {
resultTextView.setText("Please enter both numbers");
}
}
}
OUTPUT:

You might also like