Untitled
unknown
java
24 days ago
1.0 kB
12
Indexable
Never
public class OrderService { private Database database; public OrderService() { this.database = new Database(); } public void placeOrder(String customerId, String productId, int quantity) { if (customerId == null || productId == null || quantity <= 0) { System.out.println("Invalid order details"); return; } Customer customer = database.findCustomerById(customerId); if (customer == null) { System.out.println("Customer not found"); return; } Product product = database.findProductById(productId); if (product == null || product.getStock() < quantity) { System.out.println("Product not available"); return; } Order order = new Order(customer, product, quantity); database.saveOrder(order); product.setStock(product.getStock() - quantity); database.updateProduct(product); System.out.println("Order placed successfully"); } }
Leave a Comment