李昊亿 1 year ago
parent cbb458cba8
commit 7e4892792f

@ -0,0 +1,32 @@
public class MembershipDiscount {
public static void main(String[] args) {
// 假设会员的积分分别为1500、3000和5000
int[] memberPoints = {1500, 3000, 5000};
for (int points : memberPoints) {
double discountedPrice = calculateDiscountedPrice(points);
System.out.printf("会员积分:%d折扣后价格%.2f\n", points, discountedPrice);
}
}
/**
*
*
* @param points
* @return
*/
public static double calculateDiscountedPrice(int points) {
double price = 100.0; // 假设商品原价为100元根据需要可以修改
if (points < 2000) {
price = price * 0.9; // 积分小于2000分打9折
} else if (points >= 2000 && points < 4000) {
price = price * 0.8; // 积分大于等于2000分且小于4000分打8折
} else if (points >= 4000) {
price = price * 0.7; // 积分大于等于4000分打7折
}
return price;
}
}
Loading…
Cancel
Save