Mobile Application
ANSWER
package com.example.tickethub;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// Declare UI components
private ImageView imageView;
private TextView titleTextView, totalCostTextView;
private EditText numTicketsEditText;
private Spinner eventSpinner;
private Button calculateButton;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI components
imageView = findViewById(R.id.imageView);
titleTextView = findViewById(R.id.titleTextView);
totalCostTextView = findViewById(R.id.totalCostTextView);
numTicketsEditText = findViewById(R.id.numTicketsEditText);
eventSpinner = findViewById(R.id.eventSpinner);
calculateButton = findViewById(R.id.calculateButton);
// Set up the spinner with event options
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.event_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
eventSpinner.setAdapter(adapter);
// Set an item selected listener for the spinner
eventSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// Handle spinner item selection if needed
}
public void onNothingSelected(AdapterView<?> parentView) {
// Do nothing here
}
});
// Set a click listener for the calculate button
calculateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
calculateTotalCost();
}
});
}
private void calculateTotalCost() {
// Get the number of tickets entered by the user
String numTicketsStr = numTicketsEditText.getText().toString();
int numTickets = Integer.parseInt(numTicketsStr);
// Fixed ticket cost per ticket
double ticketCost = 59.99;
// Calculate the total cost
double totalCost = numTickets * ticketCost;
// Display the total cost
totalCostTextView.setText("Total Cost: $" + totalCost);
}
}
In this code, we have defined the necessary UI components and set up the spinner with event options as specified in your requirements. The calculateTotalCost
method calculates the total cost based on the number of tickets entered by the user and displays it in the totalCostTextView
.
You will need to create the layout XML file (e.g., activity_main.xml
) that corresponds to this code and includes the required UI components.
Additionally, you’ll need to create the appropriate resource files, such as strings, and add them to your project as needed. Please adapt this code to your specific project and make sure to add your custom icon and theme to your Android app accordingly.
QUESTION
Description
In this app, the user will select an event, enter data, and the mobile app will conduct data processing by performing mathematical calculations. The mobile app details are below: Using Android Studio
- Mobile Application Title: “Ticket Hub”
- Overview: Provide an app that will calculate the total cost of concert tickets for the user. The user will select the event name, enter the number of tickets, and find the cost via a button.
- Requirements:
- The app will include a single screen – create your own layout
- App must have a custom icon – use an icon of your choosing
- Apply a theme to the app screen
- The opening screen contains the following:
- Large title named Concert Ticket Hub using a TextView.
- Image using an ImageView
- Button control to calculate the cost (concert tickets are $59.99 each, regardless of the event)
- A Number Text Field control to allow the user to enter the number of tickets.
- A Spinner control that includes three events:
- Pop Music Festival
- Jazz Music Festival
- Country Music Festival.
- A TextView to display the total cost for the tickets
- When the calculate button is clicked, the total cost for the tickets is displayed
- Conditions/Instructions: Use a theme, a title, an image, a spinner prompt, a string array, a custom icon, and a hint property.
Submit screen captures of the mobile app being emulated and the code of the ActivityMain.java file (be sure to include a comment in your code with your name and date).
Save your file as Week2_PA1_your name. Submit your assignment using the Submission instructions below. Screen captures must include:
- App running in an emulator showing all required components
- App running in an emulator showing spinner control open showing all events listed
- App running in an emulator showing total cost calculated
- Emulator app screen showing custom app launcher icon
- java code (including comment with your name and date at the top of the file)