Question: Program needs to be written in Java, having trouble with this. C . Interface: Create an interface PaymentMethod that consists of the following prototypes: boolean
Program needs to be written in Java, having trouble with this.
C Interface:
Create an interface PaymentMethod that consists of the following prototypes:
boolean processPaymentdouble amount: to process the payment and return true if the
payment was successful, false otherwise.
void printReceipt to print a receipt for the transaction
Create a class CreditCardPayment that implements PaymentMethod. The class should include
the field cardNumber and cardHolderName both as String. Implement the following methods:
processPayment to print "Processing credit card payment..." and returns true
printReceipt to print a receipt showing the card number masking all but the last digits
and the cardholder's name
Create a class DebitCardPayment that implements PaymentMethod. The class should include
the field cardNumber and bankName both as String. Implement the following methods:
processPayment to print "Processing debit card payment..." and returns true
printReceipt to print a receipt showing the card number masking all but the last digits
and the bank name
Create a class PayPalPayment that implements PaymentMethod. The class should include the
field email as String. Implement the following methods:
processPayment to print "Processing PayPal payment for email and returns true
printReceipt to print a receipt showing the email address
Design a main program to:
Create an array of PaymentMethod objects, including instances of CreditCardPayment,
DebitCardPayment, and PayPalPayment
Loop through the array, process payments for each method, and print the receipts
Handle the case where a payment fails simulate failure by returning false for a specific
ease
The output should be similar as follow:
Processing credit card payment...
Receipt:
Cardholder: John Doe
Processing debit card payment...
Receipt:
Bank: XYZ Bank
Processing PayPal payment for
johngexample.com...
Receipt: PayPal Account:
john@example.com
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
