Android-PB 2 - System
Android-PB 2 - System
• activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<EditText android:id="@+id/editId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ID"
tools:layout_editor_absoluteY="16dp"
tools:ignore="Autofill,MissingConstraints" />
<EditText android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp" android:hint="Name"
app:layout_constraintTop_toTopOf="parent" />
<EditText android:id="@+id/editAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Age"
app:layout_constraintTop_toBottomOf="@+id/editName" />
<Button android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:text="Add
Student"
app:layout_constraintTop_toBottomOf="@+id/editAge"
tools:ignore="MissingConstraints" tools:layout_editor_absoluteX="20dp"
/>
<Button android:id="@+id/btndelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:text="Delete Student"
app:layout_constraintTop_toBottomOf="@+id/btnAdd"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="198dp" />
1|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
<Button android:id="@+id/btnupdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Update Student"
app:layout_constraintTop_toBottomOf="@+id/btndelete"
tools:ignore="MissingConstraints" tools:layout_editor_absoluteX="16dp"
/>
<Button android:id="@+id/btnview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="View Students"
app:layout_constraintTop_toBottomOf="@+id/btnupdate"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="195dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
• Mainactivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new database(this);
ed1=findViewById(R.id.editId);
ed2=findViewById(R.id.editName); ed3 =
findViewById(R.id.editAge); btnAdd =
findViewById(R.id.btnAdd);
btnUpdate = findViewById(R.id.btnupdate);
btnDelete = findViewById(R.id.btndelete);
btnView = findViewById(R.id.btnview);
if (db.insertStudent(studentName, studentAge)) {
showToast("Student added to the database.");
} else {
showToast("Error adding the student.");
}
}
});
2|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
if (studentIdStr.trim().isEmpty()) {
showToast("Please enter a valid student ID for deletion."); return;
}
int studentId = Integer.parseInt(studentIdStr);
boolean deleted = db.deleteStudent(studentId);
if (deleted) {
showToast("Student deleted from the database.");
} else {
showToast("Error deleting the student.");
}
}
});
btnUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String studentIdStr = ed1.getText().toString(); String
studentName = ed2.getText().toString(); String
studentAgeStr = ed3.getText().toString();
if (data.getCount() == 0) {
showToast("No students in the database."); return;
}
3|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
}
}
• Datatabase.java
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + " (" + COL_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_NAME +
" TEXT, " +
COL_AGE + " INTEGER)";
db.execSQL(createTable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
4|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
return db.query(TABLE_NAME, null, null, null, null, null, null);
}
• OUTPUT
2. Create an application that designs a layout having text boxes and button submit. The details of
doctor like doctor’s first name, last name, mobile number, address, city and specialization should
be entered by the user in the textboxes and on clicking on the button submit the data should be
saved into the database. Create another layout that contains a text box, a button search and a
text view that gives searching facility. User can search doctor’s full information by providing
doctor’s name in the text box. On clicking on button search the information of the doctor should
be displayed in text view. Doc_detail (doc_id, firstname, lastname, mob, add, city, specialization)
• activity_main.xml
5|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
android:text="Doctor Details"
android:textColor="@color/black"
android:textSize="25dp" android:textStyle="bold"
tools:ignore="MissingConstraints" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp">
<EditText
android:id="@+id/edtFN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:hint="first name" />
<EditText
android:id="@+id/edtLN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:hint="last name" />
<EditText android:id="@+id/edtMoNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp" android:hint="mobile no" />
<EditText android:id="@+id/edtadd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp" android:hint="address" />
<EditText android:id="@+id/edtcity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:hint="city" />
<EditText android:id="@+id/edtSpecializ"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp" android:hint="specialization"
/>
<Button android:id="@+id/btnp2submit"
android:layout_width="wrap_content"
6|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="submit" />
<Button android:id="@+id/btnp2search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="Search" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
• MainActivity.java
7|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
• activity_search_p2.xml
<LinearLayout android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
tools:ignore="MissingConstraints">
<EditText android:id="@+id/edtsearch"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp" android:hint="Search doctor
name..." />
<Button android:id="@+id/btnp2search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="Search" />
</LinearLayout>
<TextView
android:id="@+id/tvsearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="No more
search" android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
• searchp2.java
editTextSearch;
Button searchButton;
TextView textViewSearchResult; DoctorDatabaseP2
doctorDatabaseP2;
@SuppressLint("MissingInflatedId") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_p2);
doctorDatabaseP2 = new DoctorDatabaseP2(this);
• DoctorDatabaseP2.java
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE IF NOT EXISTS " + TABLE_DOCTOR + " (" + COLUMN_DOC_ID + " INTEGER
PRIMARY KEY AUTOINCREMENT, " + COLUMN_FIRST_NAME + " TEXT, " +
COLUMN_LAST_NAME + " TEXT, " +
COLUMN_MOBILE + " TEXT, " +
COLUMN_ADDRESS + " TEXT, " + COLUMN_CITY
+ " TEXT, " + COLUMN_SPECIALIZATION + "
9|Page
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
TEXT);";
db.execSQL(createTable);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { String sql =
"DROP TABLE IF EXISTS " + TABLE_DOCTOR;
db.execSQL(sql); onCreate(db); }
}
public void insertData(String fName,String lName ,String moNo,String address,String city,String specialization ) {
SQLiteDatabase db = this.getWritableDatabase(); ContentValues
contentValues = new ContentValues();
contentValues.put(COLUMN_FIRST_NAME, fName);
contentValues.put( COLUMN_LAST_NAME,lName);
contentValues.put( COLUMN_MOBILE,moNo); contentValues.put(
COLUMN_ADDRESS,address); contentValues.put(
COLUMN_CITY,city);
contentValues.put( COLUMN_SPECIALIZATION,specialization);
db.insert(TABLE_DOCTOR, null, contentValues); db.close();
}
public Cursor searchDoctor(String name) { SQLiteDatabase db =
this.getReadableDatabase();
String sql = "SELECT * FROM " + TABLE_DOCTOR + " WHERE " + COLUMN_FIRST_NAME + " LIKE '%"
+ name + "%'" ;
return db.rawQuery(sql, null);
}
}
• OUTPUT
10 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
3. Create an application that designs a layout which provides field for enrollment number (text
box), student’s name (text box), course (radio buttons), semester (radio buttons)) and marks for
sub1 (text box), sub2 (text box), sub3 (text box) and a button name submit. When user clicks on
submit button data should be added to database.
• activity_main.xml
tools:ignore="MissingConstraints" />
<EditText android:id="@+id/studentName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Student's Name"
/>
<RadioGroup
android:id="@+id/courseRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/studentName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.1">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Course"
tools:ignore="MissingConstraints" />
<RadioButton
android:id="@+id/bca"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true" android:text="BCA"/>
<RadioButton android:id="@+id/bscint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BSC(int)" />
11 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
<RadioButton android:id="@+id/bsccyber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BSC cyber" />
</RadioGroup>
<RadioGroup android:id="@+id/semesterRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/courseRadioGroup"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.1">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Student registration"
tools:ignore="MissingConstraints" />
<RadioButton android:id="@+id/semester1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="Semester 1" />
<RadioButton android:id="@+id/semester2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Semester 2" />
<RadioButton android:id="@+id/semester3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Semester 3" />
</RadioGroup>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@+id/semesterRadioGroup">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject Marks" />
<EditText
android:id="@+id/sub1Marks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="" android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/semesterRadioGroup" />
<EditText android:id="@+id/sub2Marks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="" android:inputType="number"
app:layout_constraintTop_toBottomOf="@+id/sub1Marks"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText android:id="@+id/sub3Marks"
android:layout_width="match_parent"
12 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
android:layout_height="wrap_content"
android:hint="" android:inputType="number"
app:layout_constraintTop_toBottomOf="@+id/sub2Marks"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button android:id="@+id/submitBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Submit Student"
app:layout_constraintTop_toBottomOf="@+id/sub3Marks"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp" />
<Button android:id="@+id/btnview"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="View"
app:layout_constraintTop_toBottomOf="@+id/submitBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
• MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText enrollmentNumber,studentName,sub1Marks,sub2Marks,sub3Marks; RadioGroup
courseRadioGroup,semesterRadioGroup; StudentDatabaseHelper db;
Button submitBtn,buttonview; @Override
13 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
buttonview = findViewById(R.id.btnview);
submitBtn.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
String enrollment = enrollmentNumber.getText().toString(); String name =
studentName.getText().toString();
RadioButton selectedCourse = findViewById(courseRadioGroup.getCheckedRadioButtonId()); String course =
selectedCourse.getText().toString();
RadioButton selectedSemester = findViewById(semesterRadioGroup.getCheckedRadioButtonId());
String semester = selectedSemester.getText().toString(); int sub1 =
Integer.parseInt(sub1Marks.getText().toString()); int sub2 =
Integer.parseInt(sub2Marks.getText().toString()); int sub3 =
Integer.parseInt(sub3Marks.getText().toString());
• activity_viewdata.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
>
<TableLayout android:id="@+id/recordTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*">
14 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
<TableRow>
<TextView android:text="Enrollment"
android:gravity="center"
android:layout_weight="1"/>
<TextView android:text="Name"
android:gravity="center"
android:layout_weight="1"/>
<TextView android:text="Course"
android:gravity="center"
android:layout_weight="1"/>
<TextView android:text="Semester"
android:gravity="center"
android:layout_weight="1"/>
<TextView android:text="Total
Marks" android:gravity="center"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
• viewdata.java
15 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
nameTextView.setText(cursor.getString(cursor.getColumnIndexOrThrow(StudentDatabaseHelper.COL
_NAME)));
row.addView(nameTextView);
courseTextView.setText(cursor.getString(cursor.getColumnIndexOrThrow(StudentDatabaseHelper.COL
_COURSE)));
row.addView(courseTextView);
TextView semesterTextView = new TextView(this);
semesterTextView.setText(cursor.getString(cursor.getColumnIndexOrThrow(StudentDatabaseHelper.C OL_SEMESTER)));
row.addView(semesterTextView);
int sub1Marks = cursor.getInt(cursor.getColumnIndexOrThrow(StudentDatabaseHelper.COL_SUB1_MARKS));
int sub2Marks = cursor.getInt(cursor.getColumnIndexOrThrow(StudentDatabaseHelper.COL_SUB2_MARKS));
int sub3Marks = cursor.getInt(cursor.getColumnIndexOrThrow(StudentDatabaseHelper.COL_SUB3_MARKS));
• StudentDatabaseHelper.java
16 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
• OUTPUT :
4. Create an application that designs a layout to store Result Details for BCA/BSC IT. The layout
must contain details like name (textbox), Sem 1 Marks(spinner), Sem 2 Marks(spinner), Sem 3
Marks(spinner) , Sem 4 Marks(spinner), Sem 5 Marks(spinner) , Sem 6 Marks(spinner) and a
Button named Submit.
Note: Marks must be from (AA, AB, BB, BC, CC and FF) When the submit button is selected all the details should be
saved in the database.
Also provide a layout to perform the following operations:
a. Update the Marks/grade.
b. Search the Students on basis of his marks / grade.
• Activity_main.Xml
17 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />
<Spinner android:id="@+id/spinnerSem1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/marks_array" />
<EditText android:id="@+id/etNewMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="New Marks" />
<Spinner android:id="@+id/spinnerSearchMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />
<Button android:id="@+id/btnUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update Marks" />
<Button android:id="@+id/btnSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search Students" />
<Button android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ButtonView" />
<EditText android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Your Id"
android:inputType="text" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
• MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
18 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter; import
android.widget.Button; import
android.widget.EditText; import
android.widget.Spinner; import
android.widget.Toast;
eName, eNewMarks;
Spinner spinnersem1, spinnerSearchMarks;
Button btnSubmit, btnUpdate, btnSearch, btnView;
ArrayAdapter<String> marksAdapter; DatabaseHelperquesion4 db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
19 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
values.put("sem1_marks", sem1Marks);
long newRowId = database.insert("result_details", null, values); if
(newRowId != -1) {
showToast("Data inserted successfully.");
} else {
showToast("Error occurred while inserting data.");
}
}
private void updateMarks(String studentName, String newMarks) { SQLiteDatabase
database = db.getWritableDatabase(); ContentValues values = new
ContentValues(); values.put("sem1_marks", newMarks);
String selection = "name=?";
String[] selectionArgs = {studentName};
0) {
20 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
int id = cursor.getInt(idColumnIndex); studentsList.append("ID:
").append(id).append(", ");
}
if (nameColumnIndex != -1) {
String name = cursor.getString(nameColumnIndex); studentsList.append("Name:
").append(name).append(", ");
}
if (sem1MarksColumnIndex != -1) {
String sem1Marks = cursor.getString(sem1MarksColumnIndex);
studentsList.append("Sem1 Marks: ").append(sem1Marks);
}
studentsList.append("\n");
} while (cursor.moveToNext());
} else {
studentsList.append("No students found.");
}
showToast(studentsList.toString());
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
• Array.xml
• DatabaseHelperquesion4.xml
• OUTPUT
5. Create an application that designs a layout to store Student Details. The layout should contain
information like: Roll number (textbox), Name (textbox), Birth date (Date Picker), Marks1
(textbox), Marks2 (textbox), Marks3 (textbox) and button submit. When button submit is clicked
than all the details must be saved in the database. Also percentage and total should be
calculated automatically and saved into the database.
Also design a layout to perform following operations:
a) Update Any student’s marks
b) Search the student details by roll no
c) Delete any student by roll no
• Activity_main.xml
22 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:ignore="MissingConstraints">
<EditText
android:id="@+id/edRollNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
android:hint="Roll no"/>
<EditText
android:id="@+id/edSName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp" android:hint="Student
name" />
<TextView android:id="@+id/edTest"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:textSize="18sp"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp" android:hint="Select Date"
/>
<EditText android:id="@+id/edMarks1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp" android:hint="Marks 1"/>
<EditText android:id="@+id/edMarks2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp" android:hint="Marks 2" />
<EditText android:id="@+id/edMarks3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp" android:hint="Marks 3" />
<Button android:id="@+id/btnP5submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="Submit"/>
<Button android:id="@+id/searchP5t"
23 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="Search"/>
<Button android:id="@+id/updateP5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="update"/>
<Button android:id="@+id/deleteP5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:backgroundTint="#008080" android:text="delete"/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
• MainActivity.java
package com.example.myapplication;
android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle; import
android.view.View; import
android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;
import java.util.Calendar;
dbhelper=new DatabaseHelpers(this);
rollno=findViewById(R.id.edRollNo);
stdname=findViewById(R.id.edSName);
dataText=findViewById(R.id.edTest);
mrk1=findViewById(R.id.edMarks1);
mrk2=findViewById(R.id.edMarks2);
mrk3=findViewById(R.id.edMarks3);
submit=findViewById(R.id.btnP5submit);
24 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
search=findViewById(R.id.searchP5t);
updated=findViewById(R.id.updateP5);
deleted=findViewById(R.id.deleteP5);
dataText.setText(date);
}
},year,month,day);
dialog.show();
}
});
String dates = day + "/" + month + "/" + year;
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String Rollno = rollno.getText().toString();
String studentname = stdname.getText().toString(); String m1 =
mrk1.getText().toString();
String m2 = mrk2.getText().toString(); String m3
= mrk3.getText().toString();
int total = Integer.parseInt(m1) + Integer.parseInt(m2) + Integer.parseInt(m3); double per =
total/3;
try {
dbhelper.insertData(Rollno,studentname,dates,m1,m2,m3,total,per);
Toast.makeText(MainActivity.this,"Student Result added to the database.",Toast.LENGTH_SHORT).show();
}catch (Exception exception)
{
Toast.makeText(MainActivity.this,"Error in adding Student Result.",Toast.LENGTH_SHORT).show();
}
}
});
search.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, searchP5.class); startActivity(intent);
}
});
if (studentId.trim().isEmpty()){
Toast.makeText(MainActivity.this,"Please enter a valid student ID for updating.",Toast.LENGTH_SHORT).show();
return;
}else {
try {
dbhelper.updateStudent(studentId,marks1,marks2,marks3); Toast.makeText(MainActivity.this, "Student
information updated successfully.",
Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(MainActivity.this, "Error updating the student information.", Toast.LENGTH_SHORT).show();
}
}
}
});
dbhelper.deleteStudent(studentId);
Toast.makeText(MainActivity.this, "Student deleted from the database.", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Error deleting the student.", Toast.LENGTH_SHORT).show();
}
}
});
26 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
}
}
• activity_search_p5.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp">
<EditText android:id="@+id/edtSearchP5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:hint="search Roll Number ..."
/>
<Button android:id="@+id/btnP5Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
</LinearLayout>
<TextView android:id="@+id/tvSearchP5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:text="no more search"
android:textColor="@color/black"
android:textSize="20dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
• searchP5.java
27 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
dbHelper;
@SuppressLint("MissingInflatedId") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_p5);
} while (cursor.moveToNext());
}
}
});
}
}
• DatabaseHelpers.java
28 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
public static final String STUDENT_NAME = "student_name";
public static final String BIRTHDAY_DATE = "birthday_date"; public static
final String MARKS1 = "marks1";
public static final String MARKS2 = "marks2"; public
static final String MARKS3 = "marks3"; public static
final String TOTAL = "total";
public static final String PERCENTAGE = "percentage";
@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE IF NOT EXISTS " + Student_details + " (" + Student_id + " INTEGER PRIMARY
KEY AUTOINCREMENT, " + ROLL_NO + " TEXT, " + STUDENT_NAME + " TEXT , " + BIRTHDAY_DATE + " TEXT , " + MARKS1 + "
TEXT , " + MARKS2 + " TEXT , " + MARKS3 + " TEXT , " + TOTAL + " INTEGER , " + PERCENTAGE + " DOUBLE);";
db.execSQL(createTableQuery);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public void insertData(String roll_no, String std_name, String BDay, String mrk1, String mrk2, String mrk3, int total, double
per) {
SQLiteDatabase db = this.getWritableDatabase();
public void updateStudent(String rollNo, String mrk1, String mrk2, String mrk3) { SQLiteDatabase db
= this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(MARKS1, mrk1); contentValues.put(MARKS2,
mrk2); contentValues.put(MARKS3, mrk3);
db.update(Student_details, contentValues, ROLL_NO + "=?", new String[]{String.valueOf(rollNo)}); db.close();
}
public void deleteStudent(String name) { SQLiteDatabase db =
this.getWritableDatabase();
db.delete(Student_details, ROLL_NO + "=?", new String[]{String.valueOf(name)});
29 | P a g e
Class: TYBCA SEM-5 Subject: MOBILE APPLICATION DEVELOPMENT
Author: SYSTEM Enrollment No: 210202010_ _ _ _
Date: DD-MM-YYYY
}
• OUTPUT
30 | P a g e