using System;
using System.Collections.Generic;
public interface IPaymentMethod
{
decimal TransactionFee { get; }
void ProcessPayment(decimal amount);
}
public abstract class Payment
{
public string PayeeName { get; set; }
public Payment(string payee)
{
PayeeName = payee;
}
public virtual void DisplayInfo()
{
Console.WriteLine($"Paying {PayeeName} via {this.GetType().Name}");
}
}
public class CreditCardPayment : Payment, IPaymentMethod
{
public CreditCardPayment(string payee) : base(payee) { }
public decimal TransactionFee => 2.5m;
public void ProcessPayment(decimal amount)
{
decimal total = amount + (amount * TransactionFee / 100);
DisplayInfo();
Console.WriteLine($"Original: ${amount:F2} | Fee: {TransactionFee}% | Total: ${total:F2}\n");
}
}
public class PayPalPayment : Payment, IPaymentMethod
{
public PayPalPayment(string payee) : base(payee) { }
public decimal TransactionFee => 3.0m;
public void ProcessPayment(decimal amount)
{
decimal total = amount + (amount * TransactionFee / 100);
DisplayInfo();
Console.WriteLine($"Original: ${amount:F2} | Fee: {TransactionFee}% | Total: ${total:F2}\n");
}
}
public class BankTransferPayment : Payment, IPaymentMethod
{
public BankTransferPayment(string payee) : base(payee) { }
public decimal TransactionFee => 1.0m;
public void ProcessPayment(decimal amount)
{
decimal total = amount + (amount * TransactionFee / 100);
DisplayInfo();
Console.WriteLine($"Original: ${amount:F2} | Fee: {TransactionFee}% | Total: ${total:F2}\n");
}
}
class Program
{
static void Main()
{
List payments = new List
{
new CreditCardPayment("John"),
new PayPalPayment("Jane"),
new BankTransferPayment("Mike")
};
decimal[] amounts = { 100, 200, 500 };
for (int i = 0; i < payments.Count; i++)
{
payments[i].ProcessPayment(amounts[i]);
}
}
}