Complete the code to declare the PaymentStrategy interface.
interface [1] {
void pay(int amount);
}The interface name should be PaymentStrategy to follow the pattern naming.
Complete the code to implement the pay method in CreditCardPayment class.
class CreditCardPayment implements PaymentStrategy { public void [1](int amount) { System.out.println("Paid " + amount + " using Credit Card."); } }
The method must be named pay to implement the interface method.
Fix the error in the PaymentContext constructor to accept a PaymentStrategy.
class PaymentContext { private PaymentStrategy strategy; public PaymentContext([1] strategy) { this.strategy = strategy; } }
The constructor parameter type must be PaymentStrategy to accept any payment strategy.
Fill both blanks to complete the pay method call in PaymentContext.
class PaymentContext { private PaymentStrategy strategy; public void pay(int amount) { strategy.[1]([2]); } }
The method pay is called with the amount parameter.
Fill all three blanks to create a PaymentContext with PayPalPayment and pay 100.
PaymentStrategy strategy = new [1](); PaymentContext context = new PaymentContext([2]); context.[3](100);
Create a PayPalPayment instance, pass it as strategy to context, then call pay with amount 100.
