-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPayment.java
More file actions
75 lines (63 loc) · 2.41 KB
/
Payment.java
File metadata and controls
75 lines (63 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public abstract class Payment {
protected ShoppingBasket basket;
public Payment(ShoppingBasket basket) {
this.basket = basket;
}
// Toplam tutarı hesaplama
public double calculateTotal() {
if (basket.isEmpty){
System.out.println("Your basket is empty.");
}
double total = 0;
else{
for (BasketItem item : basket.getItems().values()) {
total += item.getQuantity() * item.getProduct().getPrice();
}
return total;
}
// Fatura oluşturma
public void generateBill() {
System.out.println("\n--- BILL ---");
System.out.println("Product Name\tQuantity\tPrice\tTotal");
System.out.println("--------------------------------------------");
double total = 0;
for (BasketItem item : basket.getItems().values()) {
double itemTotal = item.getQuantity() * item.getProduct().getPrice();
System.out.printf(
item.getProduct().getName() + " ",
item.getQuantity() + " ",
item.getProduct().getPrice()+ " ",
itemTotal);
total += itemTotal;
}
System.out.printf("--------------------------------------------\nToplam: ", total);
}
// Ödeme
public abstract void processPayment();
}
// Kredi kartı ile ödeme
class CreditCardPayment extends Payment {
private String cardNumber;
private String cardExpiry;
public CreditCardPayment(ShoppingBasket basket, String cardNumber, String cardExpiry) {
super(basket); //üst sınıftan constructor çağırmak için kullandım
this.cardNumber = cardNumber;
this.cardExpiry = cardExpiry;
}
public void processPayment() {
double total = calculateTotal();
System.out.printf("Paying by the credit card.\n" + "Total: " total);
}
}
//PayPal'ın nasıl çalıştığını bilmiyorum. Bu yüzden EFT/Havale ile ödeme yöntemi ekledim.
class EFTPayment extends Payment{
private String IBANnumber;
public EFTPayment(ShoppingBasket basket, String IBANnumber){
super(basket);
this.IBANnumber = EFTPayment;
}
public void processPayment(){
double total = calculateTotal();
System.out.println("Paying by EFT/Transfer.\n" + "Total: " + total);
}
}