Payment Processing System in Java: Explanation & Practice

Create a payment processing hierarchy

Problem summary

Create Payable interface with CreditCard and BankTransfer implementations.

Starter code

// Payable interface: boolean processPayment(double amount)
// CreditCard: adds 2.5% fee, always succeeds
// BankTransfer: no fee, fails if amount > 10000

public class Main {
    public static void main(String[] args) {
        // Test case 1: Credit card 100
        // Print: Charged: <amount with fee>
    }
}

Expected output and test cases

  • CC 100 + 2.5%
    Charged: 102.5
  • Bank transfer 5000
    Transfer: 5000.0
  • Bank transfer over limit
    Transfer failed

Hints

  1. Interface defines contract
  2. Each class handles payment differently
  3. Check amount limit for bank transfer

Related Inheritance exercises

Practice all Inheritance exercises · Run this idea in the Java compiler