Untitled
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