Files
javademos/sealed/broken/WalletNotHandled.java
T
Claude af44e59e7f sealed: make the WalletNotHandled flat fee match the other examples
NetBanking flat fee is 15 everywhere; transcripts unchanged.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TF9JWFvJSNm6HVzswzZU5a
2026-09-24 12:15:14 +00:00

17 lines
599 B
Java

public class WalletNotHandled {
sealed interface Payment permits Card, Upi, NetBanking, Wallet {} // Wallet added
record Card(long amount) implements Payment {}
record Upi(long amount) implements Payment {}
record NetBanking(long amount) implements Payment {}
record Wallet(long amount) implements Payment {}
// Same switch as before, with no default and no case for Wallet.
static long fee(Payment p) {
return switch (p) {
case Card c -> c.amount() * 2 / 100;
case Upi u -> 0;
case NetBanking n -> 15;
};
}
}