import java.util.Scanner;
public class g1 {
public static void main(String[] args) {
System.out.println("换购活动开始 \n" + "1.满50加2元换可乐 \n"
+ "2.满100加3元换500ml可乐 \n" + "3.满100加10元换5000ml可乐 \n"
+ "4.满200加20换5Wml可乐 \n" + "5.满200加40换50Wml可乐 \n" + "0.不换 \n"
+ "是否换购?");
double money,jmoney; //定义单价money,加价jmoney
String tf;
Scanner sc = new Scanner(System.in);
System.out.print("是或否:");
tf = sc.next();
if (tf.equals("是")) { // tf.equals("n")即tf的值为"n"
System.out.print("请输入金额: ");
money = sc.nextInt();
jmoney = 0;
if (money >= 50) { //判定金额是否满足换购条件
System.out.print("请选择换购项目:");
int i;
i = sc.nextInt();
switch (i) { //使用switch来选择换购
case 1:
jmoney = 2;
System.out.println("成功换购可乐0");
break;
case 2:
if (money >= 100) { //金额判定
jmoney = 3;
System.out.println("成功换购可乐1");
} else
System.out.println("金额不足。");
break;
case 3:
if (money >= 100) {
jmoney = 10;
System.out.println("成功换购可乐5");
} else
System.out.println("金额不足。");
break;
case 4:
if (money >= 200) {
jmoney = 20;
System.out.println("成功换购可乐50");
} else
System.out.println("金额不足。");
break;
case 5:
if (money >= 200) {
jmoney = 40;
System.out.println("成功换购可乐500");
} else
System.out.println("金额不足。");
break;
}
if (i == 0)
System.out.println("不换");
System.out.println("消费总金额:" + (money + jmoney));
} else
System.out.println("金额不足。");
} else
System.out.println("取消换购。");
}
}
标签: