*实现优惠卷抵用活动
*用户获得一张20元抵用卷,现有5项商品可以使用优惠卷
*用户只能选择一项进行使用
*当用户选择后,用户付钱,并找零钱
首先用输出语句答应出商品详细,使用键盘录入写你要选择的商品编号(1~5)
用switch语句写出每个商品,原价多少、用卷后多少、实付多少 。 case写出商品编号(1~5)定义一个变量 : int类型 dyj =20;抵用卷
拿商品原价减去抵用卷就是实付
定义键盘录入l1是你花费的费用 然后拿 (花费的费用-(原价-抵用卷))是找零
-------------------------------------------------------------代码区-----------------------------------------------------------
import java.util.Scanner;
public class Demolx5 {
public static void main(String[] args) {
int dyj=20;
System.out.println("-----------欢迎来到商城----------");
System.out.println("主菜单>使用抵用卷"+"\n"+"以下商品可以使用抵用卷20元:");
System.out.println("1.美的微波炉一370元"+"\n"+"2.飞利浦剃须刀一267元"+"\n"+"3.格力空调一3225元"+"\n"+"4.潮流卫衣一577元"+"\n"+"5.小姐姐网红舞教程一139元");
System.out.println("请输入您要购买的商品编号:");
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
switch (i){
case 1:
System.out.println("您选择购买美的微波炉一370元"+"\n"+"原价:"+370+"元,"+"抵用卷减"+dyj+"元,"+"现价"+(370-dyj)+"元"+"\n"+"请付款"+(370-dyj));
int i1 = scanner.nextInt();
System.out.println("找零"+(i1-(370-dyj)));
System.out.println("谢谢回顾");
break;
case 2:
System.out.println("您选择购买飞利浦剃须刀一267元"+"\n"+"原价:"+267+"元,"+"抵用卷减"+dyj+"元,"+"现价"+(267-dyj)+"元"+"\n"+"请付款"+(267-dyj));
int i2 = scanner.nextInt();
System.out.println("找零"+(i2-(267-dyj)));
System.out.println("谢谢回顾");
break;
case 3:
System.out.println("您选择购买格力空调一3225元"+"\n"+"原价:"+3225+"元,"+"抵用卷减"+dyj+"元,"+"现价"+(3225-dyj)+"元"+"\n"+"请付款"+(3225-dyj));
int i3 = scanner.nextInt();
System.out.println("找零"+(i3-(3225-dyj)));
System.out.println("谢谢回顾");
break;
case 4:
System.out.println("您选择购买潮流卫衣一577元"+"\n"+"原价:"+577+"元,"+"抵用卷减"+dyj+"元,"+"现价"+(577-dyj)+"元"+"\n"+"请付款"+(577-dyj));
int i4 = scanner.nextInt();
System.out.println("找零"+(i4-(577-dyj)));
System.out.println("谢谢回顾");
break;
case 5:
System.out.println("您选择购买小姐姐网红舞教程一139元"+"\n"+"原价:"+139+"元,"+"抵用卷减"+dyj+"元,"+"现价"+(139-dyj)+"元"+"\n"+"请付款"+(139-dyj));
int i5= scanner.nextInt();
System.out.println("找零"+(i5-(139-dyj)));
System.out.println("谢谢回顾");
break;
}
}
}