Delegate to an Interface-Typed Field
mediumQuestion 536PaymentMethod is an interface with one method, charge(double amount), which returns a line of text saying what happened. Write one class that implements it, and a Checkout class that works with ANY PaymentMethod because it only ever uses the interface type.
Requirements:
1. CardPayment (not public) implements PaymentMethod. Its constructor takes a String lastFour, the last four digits of the card.
2. CardPayment.charge(amount) returns Card ending <lastFour> charged <amount>, for example Card ending 1234 charged 9.5. Join the double straight onto the text.
3. Checkout has a constructor Checkout(PaymentMethod method) that stores the method in a field of type PaymentMethod.
4. setMethod(PaymentMethod method) replaces the stored method.
5. pay(double amount) returns whatever charge(amount) returns on the stored method. Checkout never builds the text itself and never names CardPayment.
6. Do not change PaymentMethod.
The tests also pass payment methods of their own to Checkout.
Do NOT write a main method.
Expected output
Card ending 4242 charged 12.5 Card ending 4242 charged 25.0
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...