-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe commerce.java
More file actions
43 lines (34 loc) · 1.09 KB
/
Copy pathe commerce.java
File metadata and controls
43 lines (34 loc) · 1.09 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Product[] catalog = {
new Product(1, "Laptop", 50000),
new Product(2, "Smartphone", 20000),
new Product(3, "Headphones", 1500)
};
Scanner scanner = new Scanner(System.in);
Order order = new Order();
while (true) {
System.out.println("\nAvailable Products:");
for (Product p : catalog) {
p.display();
}
System.out.print("Enter Product ID to add to cart (0 to finish): ");
int choice = scanner.nextInt();
if (choice == 0) break;
boolean found = false;
for (Product p : catalog) {
if (p.getId() == choice) {
order.addProduct(p);
found = true;
break;
}
}
if (!found) {
System.out.println("Invalid Product ID.");
}
}
order.showOrder();
scanner.close();
}
}