题目:
某商场购物可以打折,具体规则如下:
普通顾客购不满100元不打折,满100元打9折;
会员购物不满200元打8折,满200元打7.5折;
不同打折规则不累加计算。
请根据此优惠计划进行购物结算,键盘录入顾客的类别(0表示普通顾客,1表示会员)和购物的折前金额(整数即可),输出应付金额(小数类型)。
我写的代码:
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入顾客类别:");
int type = sc.nextInt(); //顾客类别
System.out.print("请输入金额:");
int price = sc.nextInt(); //折前金额
double money = 0; //应付金额
if (type == 0){
if (price < 100){
money = price;
}else {
money = price * 0.9;
}
}else if(type == 1){
if (price < 200){
money = price * 0.8;
}else {
money = price * 0.75;
}
}
System.out.println("您应付的金额:" + money);
}
}
代码有可能不是最优解答,如果有大佬也可以把更完美的代码发到评论区,或者给出优化的代码