Strategy Pattern Lab 1
Objective:
Add a gift card payment option to the existing strategy pattern implementation:
Assignment: Implement Gift Card Payment Strategy
You have been given an existing shopping cart (code in Demo section) implementation that uses the Strategy pattern for payment processing. The current implementation supports credit card and PayPal payment strategies. Your task is to extend the system to include a new payment strategy: the Gift Card payment strategy.
Requirements:
Implement a new class called
GiftCardStrategy
that implements thePaymentStrategy
interface.The
GiftCardStrategy
class should have the following attributes:cardNumber
(String): The gift card number.pin
(String): The PIN for the gift card.
Implement the
pay()
method in theGiftCardStrategy
class. The method should output a message stating that the payment amount has been deducted from the gift card balance.
Note:
You can assume that the existing classes (
CreditCardStrategy
,PayPalStrategy
, andShoppingCart
) are already implemented correctly. You can use the existing code in the previous example as a starting point for your implementation.