0% found this document useful (0 votes)
3 views

CateringServiceGUI

The document is a Java program that implements a GUI for a catering service called 'Evelyn's Chairs and Tables'. It allows users to view service inclusions, choose food bundles, add services, order balloons, and manage their orders. The program uses Swing for the interface and includes various features such as menu selection and order confirmation.

Uploaded by

Alexa Raphael
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CateringServiceGUI

The document is a Java program that implements a GUI for a catering service called 'Evelyn's Chairs and Tables'. It allows users to view service inclusions, choose food bundles, add services, order balloons, and manage their orders. The program uses Swing for the interface and includes various features such as menu selection and order confirmation.

Uploaded by

Alexa Raphael
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

package cateringservices;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class CateringServicesGUI {

static class Service {


String name;
double price;

Service(String name, double price) {


this.name = name;
this.price = price;
}
}

static ArrayList<Service> services = new ArrayList<>();


static ArrayList<Service> userOrders = new ArrayList<>();
static String chosenBundle = "";
static int bundlePax = 0;
static double bundleCostPerPax = 0;
static int balloonCount = 0;
static String balloonType = "";
static String balloonText = "";
static String balloonColor = "";
static double balloonPrice = 30.0;

public static void main(String[] args) {


// Predefined services
services.add(new Service("Photobooth", 5000));
services.add(new Service("Balloon Decorator", 2500));
services.add(new Service("Clown/Magician", 2000));
services.add(new Service("Sound System", 2000));
services.add(new Service("Photo and Video Coverage", 4500));
services.add(new Service("Tent House", 1500));

// Start the GUI


SwingUtilities.invokeLater(CateringServicesGUI::createAndShowGUI);
}

private static void createAndShowGUI() {


JFrame frame = new JFrame("Evelyn's Chairs and Tables");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 500);

JPanel panel = new JPanel();


panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

JLabel titleLabel = new JLabel("-- Welcome to Evelyn's Chairs and Tables


--");
titleLabel.setFont(new Font("Serif", Font.BOLD, 24));
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(titleLabel);

JButton displayInclusionsButton = new JButton("View Inclusions");


JButton chooseBundleButton = new JButton("Choose Bundle");
JButton addServicesButton = new JButton("Add Services");
JButton orderBalloonsButton = new JButton("Order Toy Balloons");
JButton displayOrdersButton = new JButton("Display Orders and Total Cost");
JButton completeOrdersButton = new JButton("Complete Orders");

// Add buttons to the panel


panel.add(Box.createRigidArea(new Dimension(0, 10)));
panel.add(displayInclusionsButton);
panel.add(chooseBundleButton);
panel.add(addServicesButton);
panel.add(orderBalloonsButton);
panel.add(displayOrdersButton);
panel.add(completeOrdersButton);

// Add action listeners


displayInclusionsButton.addActionListener(e -> displayInclusions());
chooseBundleButton.addActionListener(e -> chooseBundle());
addServicesButton.addActionListener(e -> addServices());
orderBalloonsButton.addActionListener(e -> orderToyBalloons());
displayOrdersButton.addActionListener(e -> displayOrderAndTotalCost());
completeOrdersButton.addActionListener(e -> completeOrders(frame));

// Add the panel to the frame


frame.add(panel);
frame.setVisible(true);
}

private static void displayInclusions() {


String inclusions = """
Inclusions of Evelyn's Chairs and Tables:
- Buffet table setup
- Chairs and tables for guests
- Complete catering equipment
- Uniformed waiters & scoopers
- Rice, water, and iced tea
""";
JOptionPane.showMessageDialog(null, inclusions, "Inclusions",
JOptionPane.INFORMATION_MESSAGE);
}

private static void chooseBundle() {


String[] bundles = {
"Bundle A: ₱350 per head",
"Bundle B: ₱450 per head",
"Bundle C: ₱500 per head"
};

String choice = (String) JOptionPane.showInputDialog(


null,
"Select a food bundle:",
"Choose Bundle",
JOptionPane.QUESTION_MESSAGE,
null,
bundles,
bundles[0]
);

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;
}
}

String paxInput = JOptionPane.showInputDialog("Enter the number of


pax:");
try {
bundlePax = Integer.parseInt(paxInput);
JOptionPane.showMessageDialog(null, "You chose " + chosenBundle + "
for " + bundlePax + " pax.");
displayBundleInclusions(chosenBundle);
selectMenuItems();
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid input for pax.");
}
}
}

private static void displayBundleInclusions(String bundleType) {


String inclusions = """
- Rice, water, and iced tea
""";

if (bundleType.equals("Bundle C")) {
inclusions += "- Soft drinks (special inclusion for Bundle C)";
}

JOptionPane.showMessageDialog(null, inclusions, "Bundle Inclusions",


JOptionPane.INFORMATION_MESSAGE);
}

private static void selectMenuItems() {


selectPastaSection();
selectMainCourses();
selectDessertSection();
JOptionPane.showMessageDialog(null, "Menu selection complete!");
}

private static void selectPastaSection() {


String[] pastas = {"Spaghetti", "Carbonara", "Pancit Canton", "Pancit
Bihon", "Pancit Palabok"};
int pastaCount = chosenBundle.equals("Bundle C") ? 2 : 1;

for (int i = 0; i < pastaCount; i++) {


String pasta = (String) JOptionPane.showInputDialog(
null,
"Choose pasta (" + (i + 1) + " of " + pastaCount + "):",
"Pasta Selection",
JOptionPane.QUESTION_MESSAGE,
null,
pastas,
pastas[0]
);
if (pasta != null) {
chosenPastas.add(pasta);
}
}
}

private static void selectMainCourses() {


String[] vegetables = {"Chopsuey", "Lumpiang Sariwa", "Lumpiang Toge",
"Buttered Mixed Vegetables", "Mixed Vegetables with Quail Egg"};
String[] chicken = {"Fried Chicken", "Cordon Bleu", "Chicken Barbecue",
"Roasted Chicken", "Chicken Fillet", "Chicken Curry"};
String[] pork = {"Lechong Kawali", "Grilled Liempo", "Tokwa't Baboy",
"Lumpiang Shanghai", "Pork Hamonado", "Pork Kaldereta"};
String[] beef = {"Beef Kaldereta", "Beef Kare-Kare", "Creamy Beef with
Mushroom", "Beef Broccoli"};
String[] seafood = {"Buttered Garlic Shrimp", "Buttered Garlic Crab",
"Baked Salmon", "Sweet and Sour Fish Fillet", "Relyenong Bangus"};

chosenMainCourses.add((String) JOptionPane.showInputDialog(null, "Choose a


vegetable main course:", "Main Course - Vegetables", JOptionPane.QUESTION_MESSAGE,
null, vegetables, vegetables[0]));
chosenMainCourses.add((String) JOptionPane.showInputDialog(null, "Choose a
chicken main course:", "Main Course - Chicken", JOptionPane.QUESTION_MESSAGE, null,
chicken, chicken[0]));
chosenMainCourses.add((String) JOptionPane.showInputDialog(null, "Choose a
pork main course:", "Main Course - Pork", JOptionPane.QUESTION_MESSAGE, null, pork,
pork[0]));
chosenMainCourses.add((String) JOptionPane.showInputDialog(null, "Choose a
beef main course:", "Main Course - Beef", JOptionPane.QUESTION_MESSAGE, null, beef,
beef[0]));

if (chosenBundle.equals("Bundle B") || chosenBundle.equals("Bundle C")) {


chosenMainCourses.add((String) JOptionPane.showInputDialog(null,
"Choose a seafood main course:", "Main Course - Seafood",
JOptionPane.QUESTION_MESSAGE, null, seafood, seafood[0]));
}
}

private static void selectDessertSection() {


String[] desserts = {"Buko Pandan", "Coffee Jelly", "Gelatin", "Mini Leche
Flan", "Fruit Salad"};
String dessert = (String) JOptionPane.showInputDialog(null, "Choose a
dessert:", "Dessert Selection", JOptionPane.QUESTION_MESSAGE, null, desserts,
desserts[0]);

if (dessert != null) {
chosenDessert = dessert;
}
}
}

private static void orderToyBalloons() {


// Select Balloon Type
String[] balloonTypes = {"Flying Balloon", "Stick Balloon"};
String selectedType = (String) JOptionPane.showInputDialog(
null,
"Choose the type of balloon:",
"Order Toy Balloons",
JOptionPane.QUESTION_MESSAGE,
null,
balloonTypes,
balloonTypes[0]
);

if (selectedType != null) {
balloonType = selectedType;

// Enter the Number of Balloons


String balloonCountInput = JOptionPane.showInputDialog("Enter the number of
balloons:");
try {
balloonCount = Integer.parseInt(balloonCountInput);

// Ask for Text on Balloons


int addTextChoice = JOptionPane.showConfirmDialog(
null,
"Do you want to add text to the balloons?",
"Text on Balloons",
JOptionPane.YES_NO_OPTION
);

if (addTextChoice == JOptionPane.YES_OPTION) {
balloonText = JOptionPane.showInputDialog("Enter the text for the
balloons:");
} else {
balloonText = ""; // No text
}

// Choose Balloon Color


String[] balloonColors = {"Red", "Orange", "Yellow", "Green", "Blue",
"Violet", "Pink", "White", "Black"};
String selectedColor = (String) JOptionPane.showInputDialog(
null,
"Choose the color of the balloons:",
"Balloon Color",
JOptionPane.QUESTION_MESSAGE,
null,
balloonColors,
balloonColors[0]
);

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);
}
}

private static void removeOrEditOrder() {


// Build the current order summary
StringBuilder orderSummary = new StringBuilder();
orderSummary.append("Current Order Summary:\n")
.append("Bundle: ").append(chosenBundle).append("\n")
.append("Pax: ").append(bundlePax).append("\n")
.append("Pasta Selections: ").append(chosenPastas).append("\n")
.append("Main Course Selections: ").append(chosenMainCourses).append("\
n")
.append("Dessert: ").append(chosenDessert).append("\n");

orderSummary.append("\nServices and Balloon Orders:\n");


if (userOrders.isEmpty() && (balloonCount == 0 || balloonType.isEmpty())) {
orderSummary.append("No additional services or balloon orders added.\n");
} else {
for (int i = 0; i < userOrders.size(); i++) {
orderSummary.append((i + 1)).append(".
").append(userOrders.get(i).name).append(" -
₱").append(userOrders.get(i).price).append("\n");
}

if (balloonCount > 0 && !balloonType.isEmpty()) {


orderSummary.append((userOrders.size() + 1)).append(".
").append(balloonCount).append(" ").append(balloonType).append("(s) - ")
.append(balloonColor).append(balloonText.isEmpty() ? "" : "
with text: \"" + balloonText + "\"").append("\n");
}
}

orderSummary.append("\nWhat would you like to do?\n")


.append("1. Remove or Edit a Service\n")
.append("2. Change the Selected Bundle\n")
.append("3. Remove or Edit Balloon Order\n")
.append("4. Return to the Main Menu\n");

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;
}
}

private static void removeOrEditService() {


// List services for removal or edit
StringBuilder serviceList = new StringBuilder("Select a service to
remove/edit:\n");
for (int i = 0; i < userOrders.size(); i++) {
serviceList.append((i + 1)).append(".
").append(userOrders.get(i).name).append(" -
₱").append(userOrders.get(i).price).append("\n");
}
serviceList.append("Enter the number of the service to remove or 0 to
cancel.");

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.");
}
}

private static void changeBundle() {


String[] bundles = {
"Bundle A: ₱350 per head",
"Bundle B: ₱450 per head",
"Bundle C: ₱500 per head"
};

String selectedBundle = (String) JOptionPane.showInputDialog(


null,
"Select a new bundle:",
"Change Bundle",
JOptionPane.QUESTION_MESSAGE,
null,
bundles,
bundles[0]
);

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;
}
}

String paxInput = JOptionPane.showInputDialog("Enter the number of pax:");


try {
bundlePax = Integer.parseInt(paxInput);
JOptionPane.showMessageDialog(null, "Bundle changed to " + chosenBundle
+ " for " + bundlePax + " pax.");
chosenPastas.clear();
chosenMainCourses.clear();
chosenDessert = "";
selectMenuItems(); // Re-select menu items for the new bundle
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Invalid input for pax.");
}
}
}

private static void removeOrEditBalloonOrder() {


if (balloonCount > 0 && !balloonType.isEmpty()) {
String balloonInfo = "Current Balloon Order: " + balloonCount + " " +
balloonType + "(s) - " +
balloonColor + (balloonText.isEmpty() ? "" : " with text: \"" +
balloonText + "\"");

String[] options = {"Edit Balloon Order", "Remove Balloon Order"};


int balloonChoice = JOptionPane.showOptionDialog(null, balloonInfo, "Manage
Balloon Order", JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

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.");
}
}

private static void displayOrderAndTotalCost() {


double totalCost = 0;

// Build the order summary


StringBuilder orderSummary = new StringBuilder();
orderSummary.append("Your Order:\n\n");

// 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);

// Show the order summary and total cost in a dialog


JOptionPane.showMessageDialog(null, orderSummary.toString(), "Order Summary and
Total Cost", JOptionPane.INFORMATION_MESSAGE);
}

public static void completeOrders() {


// Confirmation Dialog
int choice = JOptionPane.showConfirmDialog(
null,
"Are you sure you want to complete the order?",
"Complete Order Confirmation",
JOptionPane.YES_NO_OPTION
);

if (choice == JOptionPane.NO_OPTION) {
// If user chooses "No," return to the main menu
JOptionPane.showMessageDialog(null, "Returning to the main menu...");
return;
}

// Get User's Name


String userName = JOptionPane.showInputDialog(
null,
"Please enter your name to complete the order:",
"User Name",
JOptionPane.QUESTION_MESSAGE
);

if (userName == null || userName.trim().isEmpty()) {


// Handle case where the user doesn't provide a name
JOptionPane.showMessageDialog(null, "Name is required to complete the
order. Returning to the main menu...");
return;
}

// Simulate payment process and calculate the total cost


double totalCost = bundleCostPerPax * bundlePax + balloonPrice * balloonCount;

// Show total cost to the user


String totalCostMessage = String.format("Your total cost is: ₱%.2f\n",
totalCost);
JOptionPane.showMessageDialog(null, totalCostMessage, "Total Cost",
JOptionPane.INFORMATION_MESSAGE);

// Ask for downpayment amount


String downpaymentInput = JOptionPane.showInputDialog(
null,
"Enter downpayment amount (half of the total cost):",
"Downpayment",
JOptionPane.QUESTION_MESSAGE
);

// Convert downpayment input to a double


try {
double downpaymentAmount = Double.parseDouble(downpaymentInput);

// Ensure the downpayment is valid (less than or equal to the total cost)
if (downpaymentAmount <= totalCost) {
// Calculate the remaining balance
double remainingBalance = totalCost - downpaymentAmount;

// Display downpayment and remaining balance


String downpaymentMessage = String.format(
"Thank you, %s! You've made a downpayment of: ₱%.2f\nRemaining
balance: ₱%.2f",
userName, downpaymentAmount, remainingBalance
);
JOptionPane.showMessageDialog(null, downpaymentMessage, "Downpayment
Confirmation", JOptionPane.INFORMATION_MESSAGE);

// Simulate payment process


JOptionPane.showMessageDialog(null, "Your payment is being
processed.");

// Final completion message


JOptionPane.showMessageDialog(null, """
\n
• Completing Your Order •
\n
Thank you for choosing Evelyn's Chairs and Tables! Your order
is complete.
\n
""");

// 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);
}
}

You might also like