-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
53 lines (46 loc) · 2.15 KB
/
Main.java
File metadata and controls
53 lines (46 loc) · 2.15 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
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Product p1 = new Product("ID55268", "Laptop", 1000, 10);
Product p2 = new Product("ID55287", "Phone", 100, 5);
ShoppingBasket basket = new ShoppingBasket();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the product ID and quantity to add to the cart (example: ID55268, ID55287):");
while (true) {
System.out.print("Please enter the product ID (Press Q to quit): ");
String productId = scanner.nextLine();
if (productId.equalsIgnoreCase("Q")) break;
System.out.print("Enter the quantity: ");
int quantity = Integer.parseInt(scanner.nextLine());
if (productId.equals(p1.getId())) {
try {
basket.addItem(p1, quantity);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
} else if (productId.equals(p2.getId())) {
try {
basket.addItem(p2, quantity);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
} else {
System.out.println("Invalid product ID.");
}
}
System.out.println("Your Shopping Basket: ");
basket.displayBasket();
System.out.println("\nChoose the payment type: Press 1 for Credit Card, Press 2 for EFT/Transfer");
int paymentChoice = Integer.parseInt(scanner.nextLine());
if (paymentChoice == 1) {
System.out.print("Enter the credit card number: ");
String cardNumber = scanner.nextLine();
System.out.println("Payment processed with Credit Card ending in " + cardNumber.substring(cardNumber.length() - 4));
} else if (paymentChoice == 2) {
System.out.println("Payment processed via EFT/Transfer.");
} else {
System.out.println("Invalid payment choice.");
}
scanner.close();
}
}