Saol 5.
Saol 5.
ArrayList;
class Product {
this.id = id;
this.name = name;
this.price = price;
this.stock = stock;
return "ID: " + id + ", Name: " + name + ", Price: " + price + ", Stock: " + stock;
return price;
return stock;
class ShoppingCart {
public ShoppingCart() {
totalPrice = 0.0;
products.add(product);
totalPrice += product.getPrice();
if (product.getDetails().contains(productId)) {
totalPrice -= product.getPrice();
products.remove(product);
break;
}
public double calculateTotal() {
return totalPrice;
System.out.println(product.getDetails());
class User {
this.username = username;
this.password = password;
return shoppingCart;
// Create products
// Create user
user.getShoppingCart().addProduct(product1);
user.getShoppingCart().addProduct(product2);
System.out.println("Products in Cart:");
user.getShoppingCart().displayProducts();
// Checkout
user.checkout();