Syed Imran Murtaza

Software Engineer

Front-end Developer

Freelancer

Programmer

0

No products in the cart.

Syed Imran Murtaza
Syed Imran Murtaza
Syed Imran Murtaza
Syed Imran Murtaza
Syed Imran Murtaza
Syed Imran Murtaza

Software Engineer

Front-end Developer

Freelancer

Programmer

Blog Post

Java Class Problem

June 8, 2024 Blog
Java Class Problem

This Java code defines an interface Payment and two classes CreditCardPayment and PayPalPayment that implement this interface.

The Payment interface declares a method processPayment(double amount) which is implemented by both CreditCardPayment and PayPalPayment classes.

In the CreditCardPayment class, there are private fields cardNumber and cardHolderName along with a constructor to initialize them. It also implements the processPayment method to print a message indicating the processing of a credit card payment along with the card number and card holder name.

Similarly, the PayPalPayment class has a private field email and a constructor to initialize it. It implements the processPayment method to print a message indicating the processing of a PayPal payment along with the email.

The Main class contains the main method which serves as the entry point of the program. It prompts the user to input the payment amount, credit card details (card number and card holder name), and PayPal email using a Scanner. Then, it creates instances of CreditCardPayment and PayPalPayment classes with the provided details and calls the processPayment method on each instance to simulate the processing of the payments.

Finally, the Scanner object is closed to release system resources.

Write a comment