forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
40 lines (31 loc) · 1.07 KB
/
Copy pathCustomer.java
File metadata and controls
40 lines (31 loc) · 1.07 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
import java.util.Scanner;
public class Customer
{
public static void main( String[] args )
{
System.out.println("Please enter Payment Type : 'CreditCard' or 'DebitCard' or 'ByCash'");
Scanner scanner = new Scanner(System.in);
String paymentType = scanner.next();
System.out.println("Payment type is : " + paymentType);
System.out.println("\nPlease enter Amount to Pay : ");
Scanner scanner1 = new Scanner(System.in);
String amount = scanner1.next();
System.out.println("amount is : " + amount);
PaymentContext ctx = null;
ctx = new PaymentContext();
if( "CreditCard".equalsIgnoreCase(paymentType) )
{
ctx.setPaymentStrategy(new CreditCardPaymentStrategy());
}
else if( "DebitCard".equalsIgnoreCase(paymentType) )
{
ctx.setPaymentStrategy(new DebitCardPaymentStrategy());
}
else if( "ByCash".equalsIgnoreCase(paymentType) )
{
ctx.setPaymentStrategy(new ByCashPaymentStrategy());
}
System.out.println("PaymentContext has :"+ctx.getPaymentStrategy());
ctx.pay(amount);
}
}