Untitled
unknown
java
a year ago
1.2 kB
11
Indexable
public class Main {
public enum DiscountType {
Standard,
Seasonal,
Weight;
}
public static double getDiscountedPrice(double cartWeight,
double totalPrice,
DiscountType discountType) {
if (DiscountType.Weight.equals(discountType)) {
if (cartWeightIsLessOrEqual10(cartWeight)) {
return countDiscountedPrice(totalPrice, 0.06);
}
return countDiscountedPrice(totalPrice, 0.18);
}
if (DiscountType.Seasonal.equals(discountType)) {
return countDiscountedPrice(totalPrice, 0.12);
}
return countDiscountedPrice(totalPrice, 0.06);
}
public static boolean cartWeightIsLessOrEqual10(double cartWeight) {
return cartWeight <= 10;
}
private static double countDiscountedPrice(double totalPrice,
double discount) {
var totalDiscount = totalPrice * discount;
return totalPrice - totalDiscount;
}
public static void main(String[] args) {
System.out.println(getDiscountedPrice(12, 100, DiscountType.Weight));
}
}Editor is loading...
Leave a Comment