1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| import java.util.ArrayList; import java.util.List;
class Customer { private String name; private String memberID; private float balance;
public Customer(String name, String memberID, float balance) { this.name = name; this.memberID = memberID; this.balance = balance; }
public void addTransaction(Transaction transaction) { } }
class Product { private String barcode; private String name; private float price;
public Product(String barcode, String name, float price) { this.barcode = barcode; this.name = name; this.price = price; }
}
class ShoppingCart { private List<Product> items; private float total;
public ShoppingCart() { this.items = new ArrayList<>(); this.total = 0.0f; }
public void addItem(Product product) { items.add(product); total += product.getPrice(); }
public void removeItem(Product product) { items.remove(product); total -= product.getPrice(); }
public float calculateTotal() { return total; } }
class Transaction { private String dateTime; private Customer customer; private ShoppingCart cart;
public Transaction(String dateTime, Customer customer, ShoppingCart cart) { this.dateTime = dateTime; this.customer = customer; this.cart = cart; }
}
class PaymentMethod { private String type; private String cardNumber;
public PaymentMethod(String type, String cardNumber) { this.type = type; this.cardNumber = cardNumber; }
public void processPayment(float amount) { }
public boolean validateCardNumber() { return true; } }
public class AutoShopping { public static void main(String[] args) { Customer customer = new Customer("John Doe", "123456", 100.0f);
Product product1 = new Product("123", "Product 1", 10.0f); Product product2 = new Product("456", "Product 2", 20.0f); Product product3 = new Product("789", "Product 3", 15.0f);
ShoppingCart cart = new ShoppingCart();
cart.addItem(product1); cart.addItem(product2); cart.addItem(product3);
Transaction transaction = new Transaction("2022-01-01 10:00:00", customer, cart);
PaymentMethod paymentMethod = new PaymentMethod("Credit Card", "1234567890");
paymentMethod.processPayment(cart.calculateTotal());
boolean isValidCard = paymentMethod.validateCardNumber();
if (isValidCard) { customer.addTransaction(transaction);
System.out.println("Transaction Date: " + transaction.getDateTime()); System.out.println("Customer: " + transaction.getCustomer().getName()); System.out.println("Total Amount: $" + cart.calculateTotal()); System.out.println("Payment Method: " + paymentMethod.getType()); System.out.println("Payment Processed Successfully."); } else { System.out.println("Invalid card number. Payment failed."); } } }
|