Oop Final Project
Oop Final Project
(FSD-SP-163)
Eeman Asghar
(FSD-sp-161)
Awais Jameel
(Fsd-sp-184)
Semester: BSSE-2nd
Subject: OOP
Code:
package com.example.Product;
import javax.swing.*;
import java.awt.*;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
class ShoppingCart {
private List<Product> items;
public ShoppingCart() {
items = new ArrayList<>();
}
public PointOfSaleGUI() {
shoppingCart = new ShoppingCart();
initializeUI();
setVisible(true);
}
gbc.gridy++;
gbc.gridwidth = 1;
JLabel nameLabel = new JLabel("Product Name:");
inputPanel.add(nameLabel, gbc);
gbc.gridx++;
productNameField = new JTextField(15);
inputPanel.add(productNameField, gbc);
gbc.gridx = 0;
gbc.gridy++;
JLabel priceLabel = new JLabel("Product Price:");
inputPanel.add(priceLabel, gbc);
gbc.gridx++;
productPriceField = new
JFormattedTextField(NumberFormat.getNumberInstance());
productPriceField.setColumns(10);
inputPanel.add(productPriceField, gbc);
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 2;
JButton addButton = new JButton("Add to Cart");
addButton.addActionListener(e -> addProductToCart());
inputPanel.add(addButton, gbc);
gbc.gridy++;
JButton checkoutButton = new JButton("Checkout");
checkoutButton.addActionListener(e -> checkout());
inputPanel.add(checkoutButton, gbc);
panel.add(inputPanel, BorderLayout.NORTH);
add(panel);
}
if (isValidInput(productName, priceText)) {
try {
double price = Double.parseDouble(priceText);
Product product = new Product(productName, price);
shoppingCart.addItem(product);
updateCartTextArea();
updateTotalLabel();
} catch (NumberFormatException ex) {
showError("Invalid price format. Please enter a valid
number.");
}
}
clearInputFields();
}
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(PointOfSaleGUI::new);
}
}
}
Compiler: