Checkpoint 1.46.1. Fill-in-the-blank.
Improve the style of
applyDiscount()
. The original function is below, followed by a version with three blanks. Fill in the blanks so that the original functionality is preserved, but the code is easier to maintain.public static double applyDiscount(double price, String coupon) {
double discountPrice = 0;
if (coupon.equals("SAVE10")) {
discountPrice = price * 0.9;
} else if (coupon.equals("SAVE20")) {
discountPrice = price * 0.8;
} else {
discountPrice = price;
}
return discountPrice;
}
public static double applyDiscount(double price, String coupon) {
double discountRate = 0;
if (coupon.equals("SAVE10")) {
discountRate = ----Blank 1----;
} else if (coupon.equals("SAVE20")) {
discountRate = ----Blank 2----;
}
double discountPrice = price * (1- ---Blank 3---);
return discountPrice;
}
Put your responses here:
Blank 1:
Blank 2:
Blank 3: