NAME:Abdullah Bin Hossain
ID:22201260
SECTION:E(2)
import [Link];
import [Link];
class Customer {
private int customerID;
private String customerName;
public Customer(int customerID, String customerName) {
[Link] = customerID;
[Link] = customerName;
}
public int getCustomerID() {
return customerID;
}
public String getCustomerName() {
return customerName;
}
public String getCustomerDetails() {
return "Customer ID: " + customerID + ", Customer Name: " + customerName;
}
}
class Product {
private int productid;
private String productName;
private double price;
public Product(int productid, String productName, double price) {
[Link] = productid;
[Link] = productName;
[Link] = price;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
[Link] = price;
}
public int getProductid() {
return productid;
}
public String getProductName() {
return productName;
}
public String getProductInfo() {
return "Product ID: " + productid + ", Name: " + productName + ", Price: " +
price;
}
}
interface DiscountProvider {
void applyDiscount(double discountPercent);
}
interface CustomerRegistration {
void registerCustomer(Customer customer);
}
class ShoppingCart extends Product implements DiscountProvider, CustomerRegistration {
private Customer customer;
private ArrayList<Product> items = new ArrayList<>();
public ShoppingCart() {
super(0, "Cart", 0); // Default Product ID and name for the cart
}
public void addItem(Product product, int quantity) {
for (int i = 0; i < quantity; i++) {
[Link](product);
}
}
public void removeItem(Product product) {
[Link](product);
}
public void clearCart() {
[Link]();
}
public ArrayList<Product> getCartItems() {
return items;
}
public double getTotalPrice() {
double total = 0;
for (Product item : items) {
total += [Link]();
}
return total;
}
@Override
public void applyDiscount(double discountPercent) {
for (Product product : items) {
double originalPrice = [Link]();
double discountedPrice = originalPrice * (1 - (discountPercent / 100));
[Link](discountedPrice);
}
}
@Override
public void registerCustomer(Customer customer) {
[Link] = customer;
}
@Override
public String toString() {
StringBuilder cartString = new StringBuilder("Shopping Cart for Customer: ");
if (customer == null) {
[Link]("Not Registered");
} else {
[Link]([Link]());
}
[Link]("\nItems in Cart:\n");
for (Product item : items) {
[Link]([Link]()).append("\n");
}
[Link]("Total Price: ").append(getTotalPrice());
return [Link]();
}
}
public class PoS {
public static void main(String[] args) {
Scanner scan = new Scanner([Link]);
ShoppingCart cart = new ShoppingCart();
int choice;
while (true) {
[Link]("Menu:");
[Link]("1. Register Customer");
[Link]("2. Add Product to Cart");
[Link]("3. Remove Product from Cart");
[Link]("4. Apply Discount");
[Link]("5. View Cart Details");
[Link]("0. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter Customer ID: ");
int customerID = [Link]();
[Link](); // Consume newline
[Link]("Enter Customer Name: ");
String customerName = [Link]();
Customer customer = new Customer(customerID, customerName);
[Link](customer);
[Link]("Customer registered: " +
[Link]());
break;
case 2:
[Link]("Enter Product ID: ");
int productID = [Link]();
[Link](); // Consume newline
[Link]("Enter Product Name: ");
String productName = [Link]();
[Link]("Enter Product Price: ");
double productPrice = [Link]();
[Link]("Enter Quantity: ");
int quantity = [Link]();
Product product = new Product(productID, productName,
productPrice);
[Link](product, quantity);
[Link]("Added " + quantity + " x " + productName + "
to the cart.");
break;
case 3:
[Link]("Enter Product ID to remove: ");
int idToRemove = [Link]();
Product productToRemove = null;
for (Product item : [Link]()) {
if ([Link]() == idToRemove) {
productToRemove = item;
break;
}
}
if (productToRemove != null) {
[Link](productToRemove);
[Link]("Removed Product ID: " + idToRemove);
} else {
[Link]("Product not found.");
}
break;
case 4:
[Link]("Enter Discount Percentage: ");
double discountPercent = [Link]();
[Link](discountPercent);
[Link]("Applied a " + discountPercent + "%
discount.");
break;
case 5:
[Link]("Cart Details:");
[Link](cart);
break;
case 0:
[Link]("Exiting...");
break;
default:
[Link]("Invalid choice. Please try again.");
break;
}
if (choice == 0) {
break;
}
}
[Link]();
}
}
OUTPUT: