VNSGU BCA Sem 3: Mobile App Dev (305-2) Practical Solutions - April 2025 Set B
Paper Informationโ
| Attribute | Value |
|---|---|
| Subject | Mobile Application Development - I |
| Subject Code | 305-2 |
| Set | B |
| Semester | 3 |
| Month/Year | April 2025 |
| Max Marks | 25 |
| Paper | View Paper | Download PDF |
Questions & Solutionsโ
Q1: Coffee Shop Order Appโ
Max Marks: 20
Create an android app interface to make Order in Coffee Shop. Include Following Modules in app: Home Screen: It Contain List of item of Coffee Shop Payment Screen: Click on Button which moves to Payment Screen from where take input of Card No, CSV No, Card Holder Name and Pin. Display Toast message of Successful On "Payment" Button Click.
1. Concept Explanationโ
Multi-Screen Navigation using Intentsโ
An Intent in Android is a messaging object used to request an action from another app component. We use an Explicit Intent to start a secondary Activity (PaymentActivity) from our primary Activity (MainActivity) and pass selected order data using intent.putExtra().
Handling Checkboxes & Selectionsโ
We will use Checkboxes for selecting coffee items. This allows students to check multiple items, compile them into a list, and calculate a total price before proceeding to checkout.
Input Validationโ
Before finalizing payment, the input fields must be validated:
- Card Number (must not be blank and must be 16 digits).
- CVV (must be 3 digits).
- Card Holder Name (must not be empty).
- PIN (must be 4 digits).
2. Algorithm & Step-by-Step Logicโ
- Home Screen (
MainActivity):- Design a layout with three or four checkboxes (e.g., Espresso, Cappuccino, Latte).
- Add a "Proceed to Payment" Button.
- In Kotlin, detect which checkboxes are checked. Collect the selected items and total amount.
- Use an
Intentto transition toPaymentActivity, appending the order details.
- Payment Screen (
PaymentActivity):- Design input fields (
EditText) for Card Number, Card Holder Name, CVV (numeric), and PIN (numeric password type). - Add a "Pay Now" Button.
- Validate that fields are not empty and meet basic criteria (e.g. CVV length == 3).
- If valid, show a
Toast.makeText(...)with the message "Payment Successful! Order Placed."
- Design input fields (
3. Implementation Code & Outputโ
View Solution & Output
Layout File: res/layout/activity_main.xml (Home Screen)โ
<?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="24dp"
android:background="#FAF6F0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VD Coffee Corner"
android:textSize="28sp"
android:textStyle="bold"
android:textColor="#4E3629"
android:layout_gravity="center"
android:layout_marginBottom="32dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your Coffee:"
android:textSize="18sp"
android:textColor="#5D4037"
android:layout_marginBottom="16dp" />
<!-- Coffee Checkboxes -->
<CheckBox
android:id="@+id/chkEspresso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Espresso - Rs. 120"
android:textSize="16sp"
android:layout_marginBottom="8dp" />
<CheckBox
android:id="@+id/chkCappuccino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cappuccino - Rs. 150"
android:textSize="16sp"
android:layout_marginBottom="8dp" />
<CheckBox
android:id="@+id/chkLatte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Caffรจ Latte - Rs. 180"
android:textSize="16sp"
android:layout_marginBottom="32dp" />
<!-- Order Button -->
<Button
android:id="@+id/btnOrder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Proceed to Payment"
android:backgroundTint="#4E3629"
android:textColor="#FFFFFF"
android:padding="12dp"
android:textSize="16sp" />
</LinearLayout>
Kotlin File: MainActivity.kt (Home Screen)โ
package com.example.coffeeshop
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.CheckBox
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val chkEspresso: CheckBox = findViewById(R.id.chkEspresso)
val chkCappuccino: CheckBox = findViewById(R.id.chkCappuccino)
val chkLatte: CheckBox = findViewById(R.id.chkLatte)
val btnOrder: Button = findViewById(R.id.btnOrder)
btnOrder.setOnClickListener {
var totalBill = 0
val orderList = ArrayList<String>()
if (chkEspresso.isChecked) {
totalBill += 120
orderList.add("Espresso")
}
if (chkCappuccino.isChecked) {
totalBill += 150
orderList.add("Cappuccino")
}
if (chkLatte.isChecked) {
totalBill += 180
orderList.add("Latte")
}
if (orderList.isEmpty()) {
Toast.makeText(this, "Please select at least one item", Toast.LENGTH_SHORT).show()
} else {
// Navigate to Payment Screen and pass data
val intent = Intent(this, PaymentActivity::class.java).apply {
putExtra("BILL_AMOUNT", totalBill)
putStringArrayListExtra("ORDER_ITEMS", orderList)
}
startActivity(intent)
}
}
}
}
Layout File: res/layout/activity_payment.xml (Payment Screen)โ
<?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="24dp"
android:background="#FAF6F0">
<TextView
android:id="@+id/txtOrderSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order Total: Rs. 0"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#4E3629"
android:layout_marginBottom="24dp" />
<!-- Card Number Input -->
<EditText
android:id="@+id/edtCardNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Card Number (16 Digits)"
android:inputType="number"
android:layout_marginBottom="12dp" />
<!-- Card Holder Name Input -->
<EditText
android:id="@+id/edtCardHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Card Holder Name"
android:inputType="textPersonName"
android:layout_marginBottom="12dp" />
<!-- Row for CVV & PIN -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="32dp">
<EditText
android:id="@+id/edtCvv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="CVV"
android:maxLength="3"
android:inputType="numberPassword"
android:layout_marginRight="8dp" />
<EditText
android:id="@+id/edtPin"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="PIN"
android:maxLength="4"
android:inputType="numberPassword"
android:layout_marginLeft="8dp" />
</LinearLayout>
<!-- Pay Button -->
<Button
android:id="@+id/btnPay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay & Place Order"
android:backgroundTint="#4E3629"
android:textColor="#FFFFFF"
android:padding="12dp"
android:textSize="16sp" />
</LinearLayout>
Kotlin File: PaymentActivity.kt (Payment Screen)โ
package com.example.coffeeshop
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class PaymentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_payment)
// Retrieve passed parameters
val billAmount = intent.getIntExtra("BILL_AMOUNT", 0)
val txtSummary: TextView = findViewById(R.id.txtOrderSummary)
txtSummary.text = "Order Total: Rs. $billAmount"
val edtCardNumber: EditText = findViewById(R.id.edtCardNumber)
val edtCardHolder: EditText = findViewById(R.id.edtCardHolder)
val edtCvv: EditText = findViewById(R.id.edtCvv)
val edtPin: EditText = findViewById(R.id.edtPin)
val btnPay: Button = findViewById(R.id.btnPay)
btnPay.setOnClickListener {
val cardNo = edtCardNumber.text.toString().trim()
val cardHolder = edtCardHolder.text.toString().trim()
val cvv = edtCvv.text.toString().trim()
val pin = edtPin.text.toString().trim()
// 1. Check for blank fields
if (cardNo.isEmpty() || cardHolder.isEmpty() || cvv.isEmpty() || pin.isEmpty()) {
Toast.makeText(this, "Please fill in all card details", Toast.LENGTH_LONG).show()
return@setOnClickListener
}
// 2. Validate Card Number Length
if (cardNo.length != 16) {
edtCardNumber.error = "Card number must be 16 digits"
return@setOnClickListener
}
// 3. Validate CVV Length
if (cvv.length != 3) {
edtCvv.error = "CVV must be 3 digits"
return@setOnClickListener
}
// 4. Validate PIN Length
if (pin.length != 4) {
edtPin.error = "PIN must be 4 digits"
return@setOnClickListener
}
// 5. Success Action
Toast.makeText(this, "Payment Successful!", Toast.LENGTH_LONG).show()
// Finish activities and return
finish()
}
}
}
๐ก Common Examination Mistakes & Tipsโ
- Activity Registration: Any secondary Activity (
PaymentActivity) must be declared inside theAndroidManifest.xmlunder the<application>element. Forgetting this registration is the most common cause ofActivityNotFoundExceptioncrashes. - Sensitive Data inputs: Input types for CVV and PIN must be set to
numberPasswordinside the layout XML. Showing plain text values for credentials will result in lost marks for security design. - Invalid Intent Keys: Check that the key names used in
intent.putExtra("KEY", value)exactly match the string used inintent.getIntExtra("KEY", default)in the secondary activity.