-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.java
More file actions
44 lines (35 loc) · 1.71 KB
/
Runner.java
File metadata and controls
44 lines (35 loc) · 1.71 KB
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
package ecommerce;
public class Runner {
public static void main(String[] args) {
// Create a shopping cart
ShoppingCart cart = new ShoppingCart();
// Create some gaming laptop products
Product laptop1 = new Product();
laptop1.setProductId(1);
laptop1.setName("Alienware M15 R6 Gaming Laptop");
laptop1.setCost(1499.99);
laptop1.setMarkUp(0.2);
Product laptop2 = new Product();
laptop2.setProductId(2);
laptop2.setName("ASUS ROG Zephyrus G14 Gaming Laptop");
laptop2.setCost(1399.99);
laptop2.setMarkUp(0.15);
// Add gaming laptops to the cart
cart.addProduct(laptop1);
cart.addProduct(laptop2);
// Display cart contents
System.out.println("Cart Contents:");
System.out.println(cart.toString());
// Check if a product is in the cart
System.out.println(laptop1.getName()+" in Cart: " + cart.hasProduct(laptop1)); // Should be true
System.out.println(laptop2.getName()+" in Cart: " + cart.hasProduct(laptop1)); // Should be true
System.out.println("HP Laptop in Cart: " + cart.hasProduct(new Product())); // Should be false
// Calculate cart total prices
System.out.printf("Total Cart Price (before tax, market rate): $%.2f\n", cart.beforeTaxPrice());
System.out.printf("Total Cart Price (with tax and markup): $%.2f\n", cart.totalCartPrice());
// Checkout and display total cost
double totalCost = cart.checkout();
System.out.printf("Checkout Complete! Total Cost: $%.2f\n", totalCost);
System.out.println("Cart Size After Checkout: " + cart.getCartSize()); // Should be 0
}
}