IT 311 - MOBILE APPLICATION DEVELOPMENT 2
SY. 2024-2025
MIDTERM COMPILATION
STUDENT NAME: FEGARIDO, CHRISTIAN M.
SECTION: BSIT-3E1
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 1
LABORATORY ACTIVITY <3>
LESSON NAME: Creating UI Programmatically
APPLICATION NAME: E1_PROGRAM3
PROBLEM INSTRUCTIONS:
PROJECT APPLICATION COMPONENTS
MAIN ACTIVITY
XML NAME: activity_main.xml
<?xml version="1.0" encoding="utf-8"?> XML OUTPUT:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="#FFFF">
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 2
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="TICKETING APPLICATION"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:text="CONCERT:"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Spinner
android:id="@+id/concertSpinner"
android:layout_width="match_parent"
android:layout_height="48dp"
android:spinnerMode="dropdown"
android:backgroundTint="#009688"
android:popupBackground="#BDFBF5"/>
<TextView
android:text="SEAT PLAN:"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioGroup
android:id="@+id/seatPlanGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/vipRadio"
android:text="VIP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/lowerDeckRadio"
android:text="Lower Deck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/upperDeckRadio"
android:text="Upper Deck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 3
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:text="TICKET PRICE:"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/priceText"
android:textColor="@color/black"
android:text=" ₱0"
android:background="#62009688"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="QUANTITY:"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/quantityInput"
android:layout_width="match_parent"
android:layout_height="48dp"
android:inputType="number"
android:hint="Enter quantity"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:text="TOTAL PRICE:"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/totalAmountText"
android:textColor="@color/black"
android:text=" ₱0"
android:background="#62009688"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 4
android:text="ADDITIONAL
ITEMS:"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/posterCheck"
android:text="Poster - ₱700.00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/bannerCheck"
android:text="Hand Banner - ₱150.00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/photoCheck"
android:text="Photo Op - ₱300.00"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="GRAND TOTAL PRICE:"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/grandTotalText"
android:textColor="@color/black"
android:text=" ₱0"
android:background="#62009688"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<Button
android:id="@+id/processButton"
android:text="PAY TICKET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#FFFF"
android:backgroundTint="#009688"/>
</LinearLayout>
</ScrollView>
JAVA NAME: MainActivity.java
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 5
package com.example.it3e1_program3;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.Button;
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 6
import android.widget.CheckBox;
import android.widget.EditText;
import java.text.NumberFormat;
import java.util.Locale;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Spinner concertSpinner;
RadioGroup seatPlanGroup;
EditText quantityInput;
CheckBox posterCheck, bannerCheck, photoCheck;
TextView priceText, totalAmountText, grandTotalText;
Button processButton;
String[] concerts = {"DAY6's 3rd World Tour", "SB19's Simula at Wakas World Tour", "BINI's World Tour"};
double[][] prices = {
{11500, 8300, 7500}, // DAY6
{15500, 10500, 9500}, // SB19
{16500, 12800, 10300} // BINI
};
final double POSTER_PRICE = 700.00;
final double BANNER_PRICE = 150.00;
final double PHOTO_OP_PRICE = 300.00;
double selectedSeatPrice = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
concertSpinner = findViewById(R.id.concertSpinner);
seatPlanGroup = findViewById(R.id.seatPlanGroup);
quantityInput = findViewById(R.id.quantityInput);
posterCheck = findViewById(R.id.posterCheck);
bannerCheck = findViewById(R.id.bannerCheck);
photoCheck = findViewById(R.id.photoCheck);
priceText = findViewById(R.id.priceText);
totalAmountText = findViewById(R.id.totalAmountText);
grandTotalText = findViewById(R.id.grandTotalText);
processButton = findViewById(R.id.processButton);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, concerts);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
concertSpinner.setAdapter(adapter);
seatPlanGroup.setOnCheckedChangeListener((group, checkedId) -> updateTicketPrice());
concertSpinner.setOnItemSelectedListener(new android.widget.AdapterView.OnItemSelectedListener() {
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 7
@Override
public void onItemSelected(android.widget.AdapterView<?> parent, android.view.View view, int position,
long id) {
updateTicketPrice();
}
@Override
public void onNothingSelected(android.widget.AdapterView<?> parent) {}
});
quantityInput.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateTotalPrice();
}
@Override
public void afterTextChanged(Editable s) {}
});
posterCheck.setOnCheckedChangeListener((buttonView, isChecked) -> updateGrandTotal());
bannerCheck.setOnCheckedChangeListener((buttonView, isChecked) -> updateGrandTotal());
photoCheck.setOnCheckedChangeListener((buttonView, isChecked) -> updateGrandTotal());
processButton.setOnClickListener(v ->
{ if (selectedSeatPrice == 0) {
Toast.makeText(MainActivity.this, "Please select a seat plan.", Toast.LENGTH_SHORT).show();
return;
}
if (quantityInput.getText().toString().isEmpty() || Integer.parseInt(quantityInput.getText().toString()) <= 0)
{ Toast.makeText(MainActivity.this, "Please enter a valid quantity.", Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(MainActivity.this, "Your ticket payment has been successfully processed.",
Toast.LENGTH_LONG).show();
});
}
private void updateTicketPrice() {
int concertIndex = concertSpinner.getSelectedItemPosition();
int seatIndex = seatPlanGroup.getCheckedRadioButtonId();
if (seatIndex == R.id.vipRadio)
{ selectedSeatPrice = prices[concertIndex][0];
} else if (seatIndex == R.id.lowerDeckRadio)
{ selectedSeatPrice = prices[concertIndex][1];
} else if (seatIndex == R.id.upperDeckRadio)
{ selectedSeatPrice = prices[concertIndex][2];
} else {
selectedSeatPrice = 0;
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 8
}
priceText.setText(formatCurrency(selectedSeatPrice));
updateTotalPrice();
}
private void updateTotalPrice() {
if (quantityInput.getText().toString().isEmpty()) {
totalAmountText.setText(formatCurrency(0));
grandTotalText.setText(formatCurrency(0));
return;
}
int quantity = Integer.parseInt(quantityInput.getText().toString());
double totalPrice = selectedSeatPrice * quantity;
totalAmountText.setText(formatCurrency(totalPrice));
updateGrandTotal();
}
private void updateGrandTotal() {
if (quantityInput.getText().toString().isEmpty()) {
grandTotalText.setText(formatCurrency(0));
return;
}
int quantity = Integer.parseInt(quantityInput.getText().toString());
double totalPrice = selectedSeatPrice * quantity;
double additionalCost = 0;
if (posterCheck.isChecked()) additionalCost += POSTER_PRICE;
if (bannerCheck.isChecked()) additionalCost += BANNER_PRICE;
if (photoCheck.isChecked()) additionalCost += PHOTO_OP_PRICE;
double grandTotal = totalPrice + additionalCost;
grandTotalText.setText(formatCurrency(grandTotal));
}
private String formatCurrency(double amount) {
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(new Locale("en", "PH"));
return currencyFormat.format(amount).replace("PHP", "₱");
}
}
OUTPUT SEQUENCE PREVIEW
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 9
SEQUENCE 1: PREVIEW 1:
The user selects a concert from the Spinner and chooses a seat
plan (VIP, Lower Deck, or Upper Deck) using RadioButtons,
displaying the corresponding ticket price.
SEQUENCE 2: PREVIEW 2:
The user enters the ticket quantity and can select additional
items (Poster, Hand Banner, or Photo Op) using CheckBoxes.
The app calculates and displays the total price based on the seat
price, quantity, and selected items.
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 10
SEQUENCE 3: PREVIEW 3:
The user clicks "PAY TICKET", and the app calculates the
grand total, displays it in the TextView, and shows a Toast
message confirming the successful payment.
REMINDERS:
File Formatting:
o If you have additional Java (Class files only) and XML (Layout Resource files only), follow the specified format.
Program Output Sequence:
o At the end of your submission, include a preview of the program’s output in the correct sequence.
Comment Color:
o Any comments originally in red should be in black text if the required data has already been provided.
Adding a New Activity:
o If you add a new Activity, provide clear steps on how to create it before listing its Java and XML files.
o Follow the same format used in MainActivity for consistency.
IT 311-MOBILE APPLICATION DEVELOPMENT 2 Page | 11