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

par1

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

par1

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

Import javax.swing.

*;

Import java.awt.*;

Import java.util.ArrayList;

Import java.util.List;

Class Chicharon {

Protected String flavor;

Protected double price;

Protected int quantity;

Protected double total;

Public Chicharon(String flavor, double price) {

This.flavor = flavor;

This.price = price;

This.quantity = 0;

This.total = 0;

Public void setQuantity(int quantity) {

This.quantity = quantity;

This.total = quantity * price;

Public double getTotal() {

Return total;

Public String getFlavor() {

Return flavor;
}

Class PorkChicharon extends Chicharon {

Public PorkChicharon(String flavor, double price) {

Super(flavor, price);

Class CrispyMushroomChicharon extends Chicharon {

Public CrispyMushroomChicharon(String flavor, double price) {

Super(flavor, price);

Class Drink extends Chicharon {

Public Drink(String flavor, double price) {

Super(flavor, price);

Public class Foodcart {

Public static void main(String[] args) {

JFrame frame = new JFrame(“Snack ‘en Chill Food Cart”);

Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Frame.setSize(700, 500);

Frame.setLayout(new BorderLayout());
List<Chicharon> cart = new ArrayList<>();

JTextArea receiptArea = new JTextArea();

receiptArea.setEditable(false);

JScrollPane scrollPane = new JScrollPane(receiptArea);

Frame.add(scrollPane, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5));

JButton porkButton = new JButton(“Chicharon Menu”);

JButton mushroomButton = new JButton(“Mushroom Chicharon


Menu”);

JButton drinkButton = new JButton(“Drink Menu”);

JButton checkoutButton = new JButton(“Check Out”);

buttonPanel.add(porkButton);

buttonPanel.add(mushroomButton);

buttonPanel.add(drinkButton);

buttonPanel.add(checkoutButton);

frame.add(buttonPanel, BorderLayout.WEST);

porkButton.addActionListener(e -> showMenu(frame, cart,


receiptArea, “Pork Chicharon”, new PorkChicharon[]{

new PorkChicharon(“Original”, 10.00), new


PorkChicharon(“Spicy”, 10.25)

}));

mushroomButton.addActionListener(e -> showMenu(frame, cart,


receiptArea, “Crispy Mushroom Chicharon”, new
CrispyMushroomChicharon[]{

new CrispyMushroomChicharon(“Spicy Mushroom”, 50.00), new


CrispyMushroomChicharon(“Garlic Mushroom”, 55.00),
new CrispyMushroomChicharon(“Cheese Mushroom”, 52.50),
new CrispyMushroomChicharon(“Cheese Garlic”, 55.50),

new CrispyMushroomChicharon(“Salted Egg”, 52.50)

}));

drinkButton.addActionListener(e -> showMenu(frame, cart,


receiptArea, “Drinks”, new Drink[]{

new Drink(“Sprite”, 13.00), new Drink(“Coke”, 12.00), new


Drink(“C2”, 25.00), new Drink(“Minute Maid”, 16.00),

new Drink(“Smart C”, 35.00), new Drink(“Mountain Dew”,


18.00), new Drink(“Big(apple)”, 12.00), new Drink(“Big(orange)”, 12.00)

}));

checkoutButton.addActionListener(e -> checkout(frame, cart,


receiptArea));

frame.setVisible(true);

Private static void showMenu(JFrame frame, List<Chicharon> cart,


JTextArea receiptArea, String menuTitle, Chicharon[] items) {

JFrame menuFrame = new JFrame(menuTitle);

menuFrame.setSize(400, 300);

menuFrame.setLayout(new GridLayout(items.length, 1, 5, 5));

for (Chicharon item : items) {

JPanel itemPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));

JLabel label = new JLabel(item.getFlavor() + “ – P “ +


String.format(“%.2f”, item.price));

JButton addButton = new JButton(“+”);

JButton minusButton = new JButton(“-“);


JLabel quantityLabel = new JLabel(“0”);

addButton.addActionListener(e -> {

int quantity = Integer.parseInt(quantityLabel.getText());

quantity++;

quantityLabel.setText(String.valueOf(quantity));

item.setQuantity(quantity);

});

minusButton.addActionListener(e -> {

int quantity = Integer.parseInt(quantityLabel.getText());

if (quantity > 0) {

quantity--;

quantityLabel.setText(String.valueOf(quantity));

item.setQuantity(quantity);

});

JButton addToCartButton = new JButton(“Add to Cart”);

addToCartButton.addActionListener(e -> {

if (item.quantity > 0) {

cart.add(item);

receiptArea.append(item.getFlavor() + “ x” + item.quantity +
“ = P “ + String.format(“%.2f”, item.getTotal()) + “ \n”);

JOptionPane.showMessageDialog(menuFrame,
item.getFlavor() + “ added to cart!”);

} else {

JOptionPane.showMessageDialog(menuFrame, “Quantity must


be greater than 0!”);

}
});

itemPanel.add(label);

itemPanel.add(minusButton);

itemPanel.add(quantityLabel);

itemPanel.add(addButton);

itemPanel.add(addToCartButton);

menuFrame.add(itemPanel);

menuFrame.setVisible(true);

Private static void checkout(JFrame frame, List<Chicharon> cart,


JTextArea receiptArea) {

Double totalAmount = 0;

StringBuilder receipt = new StringBuilder(“------- CHECKOUT ---------\


n”);

For (Chicharon item : cart) {

totalAmount += item.getTotal();

receipt.append(item.getFlavor()).append(“ x
“).append(item.quantity).append(“ = P “).append(String.format(“%.2f”,
item.getTotal())).append(“ \n”);

Double vat = totalAmount * 0.12;

totalAmount += vat;

receipt.append(“ ----------------------------\n”)
.append(“Subtotal: P “).append(String.format(“%.2f”,
totalAmount – vat)).append(“\n”)

.append(“VAT (12%): P “).append(String.format(“%.2f”,


vat)).append(“\n”);

Int confirm = JOptionPane.showConfirmDialog(frame,


receipt.toString() + “Confirm Purchase?”, “Checkout”,
JOptionPane.YES_NO_OPTION);

If (confirm == JOptionPane.YES_OPTION) {

String receipt1 = “----------------RECEIPT----------------\n”;

For (Chicharon item : cart) {

Receipt1 += item.getFlavor() + “ x” + item.quantity + “ = P “ +


String.format(“%.2f”, item.getTotal()) + “\n”;

Receipt1 += “Subtotal: P “ + String.format(“%.2f”, totalAmount –


vat) + “\n”;

Receipt1 += “VAT (12%): P “ + String.format(“%.2f”, vat) + “\n”;

Receipt1 += “Total: P “ + String.format(“%.2f”, totalAmount) + “\


n”;

String cashStr = JOptionPane.showInputDialog(frame, “Cash


Tendered: P”);

Double cashTendered = Double.parseDouble(cashStr);

Double change = cashTendered – totalAmount;

If (change >= 0) {

Receipt1 += “Change: P “ + String.format(“%.2f”, change) + “\


n”;

JOptionPane.showMessageDialog(frame, receipt1 + “\nThank


you for your purchase!\nPlease come again!”);

} else {

JOptionPane.showMessageDialog(frame, “Not enough cash.


Please try again.”);
}

Cart.clear();

receiptArea.setText(“ “);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy