-
Notifications
You must be signed in to change notification settings - Fork 0
/
EcommerceSystem.java
68 lines (57 loc) · 2.49 KB
/
EcommerceSystem.java
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
import java.util.Scanner;
public class EcommerceSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the Ecommerce System!");
ElectronicProduct smartphone = new ElectronicProduct(1, "smartphone", 599.9f, "Samsung", 1);
ClothingProduct tShirt = new ClothingProduct(2, "T-shirt", 19.99f, "Medium", "Cotton");
BookProduct oopBook = new BookProduct(3, "OOP", 39.99f, "O'Reilly", "X Publications");
System.out.print("Enter your ID: ");
int customerId = scanner.nextInt();
scanner.nextLine();
System.out.print("please enter your name: ");
String name = scanner.nextLine();
System.out.print("please Enter your address: ");
String address = scanner.nextLine();
customer customer = new customer(customerId, name, address);
System.out.print("How many products do you want to order? ");
int numProducts = scanner.nextInt();
scanner.nextLine();
product[] products = new product[numProducts];
for (int i = 0; i < numProducts; i++) {
System.out.println("which product do you want to add " + (i + 1) + ": " + " 1-smartphone 2-T-shist 3-OOP");
int productId = scanner.nextInt();
scanner.nextLine();
switch (productId) {
case 1:
products[i] = smartphone;
break;
case 2:
products[i] = tShirt;
break;
case 3:
products[i] = oopBook;
break;
default:
System.out.println("Invalid product ID. Please try again.");
i--;
break;
}
}
cart cart = new cart(customerId, numProducts, products);
float totalPrice = 0;
for (product product : products) {
totalPrice += product.getPrice();
}
System.out.print("Do you want to place an order for the products in your cart? (Total Price: $" + totalPrice + ") (Y/N) ");
String answer = scanner.nextLine();
if (answer.equalsIgnoreCase("Y")) {
System.out.println("Here is your order summary");
order order = new order(customerId, 1, products, totalPrice);
order.printorderinfo();
} else {
System.out.println("Order cancelled.");
}
scanner.close();
}
}