forked from java8/Java8InAction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscount.java
More file actions
25 lines (19 loc) · 693 Bytes
/
Discount.java
File metadata and controls
25 lines (19 loc) · 693 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
package lambdasinaction.chap11;
import static lambdasinaction.chap11.Util.delay;
import static lambdasinaction.chap11.Util.format;
public class Discount {
public enum Code {
NONE(0), SILVER(5), GOLD(10), PLATINUM(15), DIAMOND(20);
private final int percentage;
Code(int percentage) {
this.percentage = percentage;
}
}
public static String applyDiscount(Quote quote) {
return quote.getShopName() + " price is " + Discount.apply(quote.getPrice(), quote.getDiscountCode());
}
private static double apply(double price, Code code) {
delay();
return format(price * (100 - code.percentage) / 100);
}
}