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
- Interface defines contract
- Each class handles payment differently
- Check amount limit for bank transfer
Related Inheritance exercises
- Practice Employee Hierarchy in Java
- Practice Shape Area Calculator in Java
- Practice Vehicle Speed Calculator in Java
Practice all Inheritance exercises · Run this idea in the Java compiler