Created
June 29, 2020 08:30
-
-
Save bhawna94/2430f35943363f2f0dbc8f207ecccb78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface PaymentStrategy { | |
public void pay(int amount); | |
} | |
public class CreditCardStrategy implements PaymentStrategy { | |
private String name; | |
private String cardNumber; | |
private String cvv; | |
private String dateOfExpiry; | |
public CreditCardStrategy(String nm, String ccNum, String cvv, String expiryDate){ | |
this.name=nm; | |
this.cardNumber=ccNum; | |
this.cvv=cvv; | |
this.dateOfExpiry=expiryDate; | |
} | |
@Override | |
public void pay(int amount) { | |
System.out.println(amount +" paid with credit/debit card"); | |
} | |
} | |
public class PaypalStrategy implements PaymentStrategy { | |
private String emailId; | |
private String password; | |
public PaypalStrategy(String email, String pwd){ | |
this.emailId=email; | |
this.password=pwd; | |
} | |
@Override | |
public void pay(int amount) { | |
System.out.println(amount + " paid using Paypal."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment