creditcard

mail@pastecode.io avatar
unknown
java
2 months ago
1.1 kB
2
Indexable
Never
package assignments.assignment3.payment;

public class CreditCardPayment implements DepeFoodPaymentSystem {
    // Persentase biaya transaksi untuk setiap pembayaran dengan kartu kredit.
    private static final double TRANSACTION_FEE_PERCENTAGE = 0.02;
    // Saldo tersedia dalam rekening kartu kredit.
    private double saldo;

    @Override
    public long processPayment(long amount) {
        long transactionFee = countTransactionFee(amount);
        if (saldo >= amount + transactionFee) {
            saldo -= (amount + transactionFee); // Mengurangi saldo dengan jumlah dan biaya transaksi
            return transactionFee;
        } else {
            throw new IllegalStateException("Saldo tidak cukup");
        }
    }

    // Menghitung biaya transaksi berdasarkan jumlah yang diberikan
    public long countTransactionFee(long amount) {
        return Math.round(amount * TRANSACTION_FEE_PERCENTAGE);
    }

    // Getter dan Setter
    public void setSaldo(double saldo) {
        this.saldo = saldo;
    }

    public double getSaldo() {
        return saldo;
    }
}
Leave a Comment