import java.util.Scanner; // -------- BASE CLASS -------- class Payment { double amount; Payment(double amount) { this.amount = amount; } double processPayment() { return amount; } } // -------- SUB CLASS : CREDIT CARD -------- class CreditCardPayment extends Payment { CreditCardPayment(double amount) { super(amount); } double processPayment() { return amount + (amount * 0.02); // 2% service charge } } // -------- SUB CLASS : UPI -------- class UPIPayment extends Payment { UPIPayment(double amount) { super(amount); } double processPayment() { return amount + 5; // Flat ₹5 charge } } // -------- SUB CLASS : NET BANKING -------- class NetBankingPayment extends Payment { NetBankingPayment(double amount) { super(amount); } double processPayment() { return amount + (amount * 0.015); // 1.5% service charge } } // -------- MAIN CLASS -------- public class OnlinePaymentSystem { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter payment amount: "); double amount = sc.nextDouble(); System.out.println("\nChoose Payment Method:"); System.out.println("1. Credit Card"); System.out.println("2. UPI"); System.out.println("3. Net Banking"); System.out.print("Enter choice: "); int choice = sc.nextInt(); Payment payment; // Base class reference switch (choice) { case 1: payment = new CreditCardPayment(amount); break; case 2: payment = new UPIPayment(amount); break; case 3: payment = new NetBankingPayment(amount); break; default: System.out.println("Invalid choice"); sc.close(); return; } // Dynamic method dispatch double finalAmount = payment.processPayment(); System.out.println("\nFinal Payable Amount: ₹" + finalAmount); sc.close(); } }