0% found this document useful (0 votes)
4 views2 pages

Practical N0. 15 (Order)

The document contains an Android application code that allows users to select food items (Burger, Pizza, Pasta) and displays the total price upon clicking the 'Order' button. It includes XML layout for the user interface and Java code for the main activity that handles the logic for the order summary. The app uses checkboxes for item selection and shows a toast message with the selected items and total price.
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)
4 views2 pages

Practical N0. 15 (Order)

The document contains an Android application code that allows users to select food items (Burger, Pizza, Pasta) and displays the total price upon clicking the 'Order' button. It includes XML layout for the user interface and Java code for the main activity that handles the logic for the order summary. The app uses checkboxes for item selection and shows a toast message with the selected items and total price.
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
You are on page 1/ 2

Practical N0.

15(Order) android:text="Pasta - ₹80"


android:textSize="18sp"
Activity_main.xml : android:padding="10dp"

<?xml version="1.0" encoding="utf-8"?> app:layout_constraintTop_toBottomOf="@id/ch


<androidx.constraintlayout.widget.ConstraintL kPizza"
ayout
xmlns:android="http://schemas.android.com/a app:layout_constraintStart_toStartOf="parent"
pk/res/android" />

xmlns:app="http://schemas.android.com/apk/ <Button
res-auto" android:id="@+id/btnOrder"
android:layout_width="wrap_content"
xmlns:tools="http://schemas.android.com/tool android:layout_height="wrap_content"
s" android:text="Order"
android:layout_width="match_parent" android:textSize="20sp"
android:layout_height="match_parent" android:padding="10dp"
tools:context=".MainActivity"
android:padding="20dp"> app:layout_constraintTop_toBottomOf="@id/ch
kPasta"
<CheckBox
android:id="@+id/chkBurger" app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content" />
android:layout_height="wrap_content"
android:text="Burger - ₹50" </androidx.constraintlayout.widget.Constraint
android:textSize="18sp" Layout>
android:padding="10dp"
app:layout_constraintTop_toTopOf="parent" MainActivity.java :
package com.example.practical15;
app:layout_constraintStart_toStartOf="parent"
/> import android.os.Bundle;
import android.view.View;
<CheckBox import android.widget.Button;
android:id="@+id/chkPizza" import android.widget.CheckBox;
android:layout_width="wrap_content" import android.widget.Toast;
android:layout_height="wrap_content" import
android:text="Pizza - ₹100" androidx.appcompat.app.AppCompatActivity;
android:textSize="18sp"
android:padding="10dp" public class MainActivity extends
AppCompatActivity {
app:layout_constraintTop_toBottomOf="@id/ch
kBurger" CheckBox chkBurger, chkPizza, chkPasta;
Button btnOrder;
app:layout_constraintStart_toStartOf="parent"
/> @Override
protected void onCreate(Bundle
<CheckBox savedInstanceState) {
android:id="@+id/chkPasta" super.onCreate(savedInstanceState);
android:layout_width="wrap_content" setContentView(R.layout.activity_main);
android:layout_height="wrap_content"
// Initialize checkboxes and button
chkBurger = findViewById(R.id.chkBurger); }
chkPizza = findViewById(R.id.chkPizza);
chkPasta = findViewById(R.id.chkPasta);
btnOrder = findViewById(R.id.btnOrder);

// Set button click listener


btnOrder.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
int totalPrice = 0;
StringBuilder orderSummary = new
StringBuilder("Selected Items:\n");

if (chkBurger.isChecked()) {
orderSummary.append(" Burger -
₹50\n");
totalPrice += 50;
}
if (chkPizza.isChecked()) {
orderSummary.append(" Pizza -
₹100\n");
totalPrice += 100;
}
if (chkPasta.isChecked()) {
orderSummary.append(" Pasta -
₹80\n");
totalPrice += 80;
}

if (totalPrice == 0) {
orderSummary = new
StringBuilder("No items selected!");
} else {
orderSummary.append("\nTotal
Price: ₹").append(totalPrice);
}

// Display the order summary in a Toast


Toast.makeText(MainActivity.this,
orderSummary.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}

You might also like