user

mail@pastecode.io avatar
unknown
java
a month ago
2.4 kB
1
Indexable
Never
package assignments.assignment3;

import java.util.ArrayList;
import assignments.assignment3.payment.DepeFoodPaymentSystem;

public class User {
    private String nama;
    private String nomorTelepon;
    private String email;
    private String lokasi;
    private String role;
    private ArrayList<Order> orderHistory;
    private double saldo;
    private DepeFoodPaymentSystem paymentSystem;

    public User(String nama, String nomorTelepon, String email, String lokasi, String role, DepeFoodPaymentSystem paymentSystem, double saldo) {
        this.nama = nama;
        this.nomorTelepon = nomorTelepon;
        this.email = email;
        this.lokasi = lokasi;
        this.role = role;
        this.paymentSystem = paymentSystem;
        this.saldo = saldo;
        this.orderHistory = new ArrayList<>();
    }

    // Getters and Setters
    public String getEmail() {
        return email;
    }

    public String getNama() {
        return nama;
    }

    public String getLokasi() {
        return lokasi;
    }

    public String getNomorTelepon() {
        return nomorTelepon;
    }

    public double getSaldo() {
        return saldo;
    }

    public String getRole() {
        return role;
    }

    public DepeFoodPaymentSystem getPaymentSystem() {
        return paymentSystem;
    }

    public void addOrderHistory(Order order){
        orderHistory.add(order);
    }

    public ArrayList<Order> getOrderHistory() {
        return orderHistory;
    }

    public boolean isOrderBelongsToUser(String orderId) {
        return orderHistory.stream().anyMatch(order -> order.getOrderId().equals(orderId));
    }

    // Process payment and update balance
    public void makePayment(long amount) {
        try {
            long transactionFee = paymentSystem.processPayment(amount);
            saldo -= (amount + transactionFee);
            System.out.println("Pembayaran sebesar Rp" + amount + " dan biaya transaksi Rp" + transactionFee + " telah berhasil. Saldo terbaru: Rp" + saldo);
        } catch (Exception e) {
            System.out.println("Pembayaran gagal: " + e.getMessage());
        }
    }

    // Set new payment system
    public void setPaymentSystem(DepeFoodPaymentSystem paymentSystem) {
        this.paymentSystem = paymentSystem;
        System.out.println("Sistem pembayaran telah diperbarui.");
    }
}
Leave a Comment