Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
892 B
3
Indexable
Never
public class ECommerceService {
    private Inventory inventory;
    private ShoppingCart shoppingCart;

    public ECommerceService() {
        inventory = new Inventory();
        shoppingCart = new ShoppingCart();
    }

    public List<Product> searchProducts(String productName) {
        return inventory.searchProducts(productName);
    }

    public void addProductToCart(int productId, int quantity) {
        Product product = inventory.getProductById(productId);
        if (product != null) {
            shoppingCart.addProduct(product, quantity);
            System.out.println(quantity + " x " + product.getProductName() + " added to cart.");
        } else {
            System.out.println("Product not found.");
        }
    }

    public void viewShoppingCart() {
        shoppingCart.viewCart();
    }

    public void checkout() {
        shoppingCart.checkout();
    }
}
Leave a Comment