CateringServiceGUI
CateringServiceGUI
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
if (choice != null) {
switch (choice) {
case "Bundle A: ₱350 per head" -> {
chosenBundle = "Bundle A";
bundleCostPerPax = 350;
}
case "Bundle B: ₱450 per head" -> {
chosenBundle = "Bundle B";
bundleCostPerPax = 450;
}
case "Bundle C: ₱500 per head" -> {
chosenBundle = "Bundle C";
bundleCostPerPax = 500;
}
}
if (bundleType.equals("Bundle C")) {
inclusions += "- Soft drinks (special inclusion for Bundle C)";
}
if (dessert != null) {
chosenDessert = dessert;
}
}
}
if (selectedType != null) {
balloonType = selectedType;
if (addTextChoice == JOptionPane.YES_OPTION) {
balloonText = JOptionPane.showInputDialog("Enter the text for the
balloons:");
} else {
balloonText = ""; // No text
}
if (selectedColor != null) {
balloonColor = selectedColor;
// Display Confirmation
StringBuilder confirmationMessage = new StringBuilder("You have
ordered " + balloonCount + " " + balloonType + "(s)");
if (!balloonText.isEmpty()) {
confirmationMessage.append(" with the text:
").append(balloonText);
}
confirmationMessage.append(" in ").append(balloonColor).append("
color.");
JOptionPane.showMessageDialog(null, confirmationMessage.toString(),
"Order Confirmation", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "No color selected. Order
canceled.", "Order Canceled", JOptionPane.WARNING_MESSAGE);
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid input for the number of
balloons. Order canceled.", "Order Canceled", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "No balloon type selected. Order
canceled.", "Order Canceled", JOptionPane.WARNING_MESSAGE);
}
}
String[] options = {"1. Remove/Edit Service", "2. Change Bundle", "3. Edit
Balloon Order", "4. Return to Menu"};
int choice = JOptionPane.showOptionDialog(null, orderSummary.toString(),
"Manage Order", JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
switch (choice) {
case 0: // Remove or Edit a Service
removeOrEditService();
break;
case 1: // Change the Bundle
changeBundle();
break;
case 2: // Remove or Edit Balloon Order
removeOrEditBalloonOrder();
break;
case 3: // Return to Main Menu
JOptionPane.showMessageDialog(null, "Returning to the main menu.");
break;
default:
JOptionPane.showMessageDialog(null, "Invalid choice. Returning to the
main menu.");
break;
}
}
String serviceChoiceInput =
JOptionPane.showInputDialog(serviceList.toString());
try {
int serviceChoice = Integer.parseInt(serviceChoiceInput);
if (serviceChoice > 0 && serviceChoice <= userOrders.size()) {
Service removedService = userOrders.remove(serviceChoice - 1);
JOptionPane.showMessageDialog(null, removedService.name + " has been
removed from your order.");
} else if (serviceChoice != 0) {
JOptionPane.showMessageDialog(null, "Invalid choice.");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid input.");
}
}
if (selectedBundle != null) {
switch (selectedBundle) {
case "Bundle A: ₱350 per head" -> {
chosenBundle = "Bundle A";
bundleCostPerPax = 350;
}
case "Bundle B: ₱450 per head" -> {
chosenBundle = "Bundle B";
bundleCostPerPax = 450;
}
case "Bundle C: ₱500 per head" -> {
chosenBundle = "Bundle C";
bundleCostPerPax = 500;
}
}
if (balloonChoice == 0) {
orderToyBalloons(); // Reuse the orderToyBalloons method to edit
balloon details
} else if (balloonChoice == 1) {
balloonCount = 0;
balloonType = "";
balloonColor = "";
balloonText = "";
JOptionPane.showMessageDialog(null, "Balloon order removed.");
}
} else {
JOptionPane.showMessageDialog(null, "No balloon orders to edit or
remove.");
}
}
// Food Bundle
orderSummary.append("Food Bundle: ").append(chosenBundle).append(" for
").append(bundlePax).append(" pax\n");
totalCost += bundleCostPerPax * bundlePax;
// Toy Balloons
orderSummary.append("\nToy Balloons: ").append(balloonCount).append("
").append(balloonType).append("(s) (₱").append(balloonPrice).append(" each)\n");
totalCost += balloonPrice * balloonCount;
// Additional Services
orderSummary.append("\nAdditional Services:\n");
if (!userOrders.isEmpty()) {
for (Service service : userOrders) {
orderSummary.append(" ").append(service.name).append("
(₱").append(service.price).append(")\n");
totalCost += service.price;
}
} else {
orderSummary.append(" No additional services added.\n");
}
// Total Cost
orderSummary.append("\nTotal Cost: ₱").append(totalCost);
if (choice == JOptionPane.NO_OPTION) {
// If user chooses "No," return to the main menu
JOptionPane.showMessageDialog(null, "Returning to the main menu...");
return;
}
// Ensure the downpayment is valid (less than or equal to the total cost)
if (downpaymentAmount <= totalCost) {
// Calculate the remaining balance
double remainingBalance = totalCost - downpaymentAmount;
// Exit Program
System.exit(0);
} else {
JOptionPane.showMessageDialog(null, "Downpayment cannot be greater than
the total cost.", "Invalid Downpayment", JOptionPane.ERROR_MESSAGE);
}
} catch (NumberFormatException e) {
// Handle invalid input (non-numeric values)
JOptionPane.showMessageDialog(null, "Invalid input. Please enter a valid
downpayment amount.", "Invalid Input", JOptionPane.ERROR_MESSAGE);
}
}