-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathPercentDiscountVoucher.java
More file actions
41 lines (31 loc) · 993 Bytes
/
PercentDiscountVoucher.java
File metadata and controls
41 lines (31 loc) · 993 Bytes
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
package com.programmers.springweekly.domain.voucher;
import com.programmers.springweekly.util.validator.VoucherValidator;
import java.util.UUID;
public class PercentDiscountVoucher implements Voucher {
private final UUID voucherId;
private final long discountAmount;
public PercentDiscountVoucher(UUID voucherId, long discountAmount) {
VoucherValidator.validateVoucher(
VoucherType.PERCENT,
discountAmount
);
this.voucherId = voucherId;
this.discountAmount = discountAmount;
}
@Override
public UUID getVoucherId() {
return voucherId;
}
@Override
public long discount(long beforeDiscount) {
return (long) (beforeDiscount - beforeDiscount * ((double) discountAmount / 100));
}
@Override
public long getVoucherAmount() {
return discountAmount;
}
@Override
public VoucherType getVoucherType() {
return VoucherType.PERCENT;
}
}