发布网友 发布时间:2022-04-23 07:54
共1个回答
热心网友 时间:2022-06-17 23:49
public static void main(String[] args) {
double amount = 1200;// 消费金额
boolean isTeacherOrOld = true; // 是否有教师资格证或者老人标识
BigDecimal discountEightFive = new BigDecimal("0.85");// 85折
BigDecimal discountNine = new BigDecimal("0.9");// 95折
BigDecimal discountNineFive = new BigDecimal("0.95");// 95折
BigDecimal bdAmount = new BigDecimal(Double.toString(amount));
BigDecimal calcAmount = new BigDecimal("0.00");
if (amount >= 2000) {
calcAmount = bdAmount.multiply(discountEightFive);
} else if (amount > 1000 && amount < 2000) {
calcAmount = bdAmount.multiply(discountNine);
} else {
calcAmount = new BigDecimal(Double.toString(amount));
}
if (isTeacherOrOld && amount >= 1000) {
System.out.println("消费金额:" + calcAmount.multiply(discountNineFive).toString());
} else {
System.out.println("消费金额:" + calcAmount.toString());
}
}