package chapter6;

// 定义支付接口（泛型接口）
interface Payment<T> {
    boolean pay(T amount);    // 支付方法
    T getBalance();           // 获取余额
}

// 方式一：明确类型的接口实现 - 支付宝支付
class AliPay implements Payment<Double> {
    private Double balance = 1000.0;

    @Override
    public boolean pay(Double amount) {
        if (balance >= amount) {
            balance -= amount;
            System.out.println("支付成功：" + amount + "元");
            return true;
        }
        return false;
    }

    @Override
    public Double getBalance() {
        return balance;
    }
}

// 方式二：泛型类型的接口实现 - 校园卡支付
class CampusCard<T> implements Payment<T> {
    private T balance;

    public CampusCard(T balance) {
        this.balance = balance;
    }

    @Override
    public boolean pay(T amount) {
        System.out.println("支付积分：" + amount);
        return true;
    }

    @Override
    public T getBalance() {
        return balance;
    }
}

public class Example25 {
    public static void main(String[] args) {
        // 测试支付宝支付
        AliPay aliPay = new AliPay();
        aliPay.pay(100.0);

        // 测试校园卡支付
        CampusCard<Integer> campusCard = new CampusCard<>(500);
        campusCard.pay(100);
    }
}
