-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolidPrinciples.java
More file actions
115 lines (90 loc) · 3.24 KB
/
SolidPrinciples.java
File metadata and controls
115 lines (90 loc) · 3.24 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
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
import java.util.Scanner;
interface Payment {
void pay();
}
class WalletPayment implements Payment {
private String phoneNumber;
public WalletPayment(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public void pay() {
System.out.println("Payment made using Wallet linked to phone number: " + phoneNumber);
}
}
class UPIPayment implements Payment {
private String upiId;
public UPIPayment(String upiId) {
this.upiId = upiId;
}
public void pay() {
System.out.println("Payment made using UPI ID: " + upiId);
}
}
class CardPayment implements Payment {
private String cardNumber;
private String expiry;
private String cvv;
public CardPayment(String cardNumber, String expiry, String cvv) {
this.cardNumber = cardNumber;
this.expiry = expiry;
this.cvv = cvv;
}
public void pay() {
System.out.println("Payment made using Card ending with: " + cardNumber.substring(cardNumber.length() - 4));
}
}
class PaymentProcessor {
public void processPayment(Payment payment) {
payment.pay();
}
}
public class SolidPrinciples {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the amount to pay: ");
double amount = scanner.nextDouble();
scanner.nextLine();
System.out.println("Choose payment provider:");
System.out.println("a. Paytm");
System.out.println("b. Amazon Pay");
System.out.println("c. PhonePe");
String provider = scanner.nextLine();
System.out.println("Selected Provider: " + provider);
System.out.println("Choose payment method:");
System.out.println("a. Wallet");
System.out.println("b. UPI");
System.out.println("c. Credit Card");
System.out.println("d. Debit Card");
String method = scanner.nextLine();
Payment payment = null;
switch (method.toLowerCase()) {
case "a":
System.out.print("Enter phone number: ");
String phoneNumber = scanner.nextLine();
payment = new WalletPayment(phoneNumber);
break;
case "b":
System.out.print("Enter UPI ID: ");
String upiId = scanner.nextLine();
payment = new UPIPayment(upiId);
break;
case "c": // Credit Card
case "d": // Debit Card
System.out.print("Enter Card Number: ");
String cardNumber = scanner.nextLine();
System.out.print("Enter Expiry Date (MM/YY): ");
String expiry = scanner.nextLine();
System.out.print("Enter CVV: ");
String cvv = scanner.nextLine();
payment = new CardPayment(cardNumber, expiry, cvv);
break;
default:
System.out.println("Invalid payment method selected.");
System.exit(0);
}
PaymentProcessor processor = new PaymentProcessor();
processor.processPayment(payment);
System.out.println("Payment of Rs. " + amount + " is successful!");
scanner.close();
}
}