第五章while循环结构
























































import java.util.Scanner;


public class Dwu {


public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        String name = "";//商品名称

        double price = 0.0;//商品价格

        int number = 0;//商品编号

        double paymoney = 0;//实付金额

        double discount = 0.8;//折扣

        double total = 0;//商品总价

        int No = 0;//商品数量

        System.out.println("欢迎使用MyShopping管理系统");

        System.out.println("******************************************************************\n");

        System.out.println("请选择购买商品的编号:");

        System.out.println("1.体恤\t\t2.网球鞋\t\t3.网球拍\n");

        System.out.println("******************************************************************\n\n");

         String answer = "y";

        System.out.print("请输入商品编号:");

        number = input.nextInt();


if (1<=number&&number<=4) {


switch (number) {
case 1:
name = "T恤";
price = 245;
break;
case 2:
name = "网球鞋";
price = 570;
break;
case 3:
name = "网球拍";
price = 320;
break;
}
}else {

System.out.println("对不起,没有此商品,请重新输入商品编号:");

                        number = input.nextInt();

}

System.out.print("请输入商品数量:");

                        No= input.nextInt();

System.out.println(name+"¥"+price+"\t\t"+"数量" +No+"\t"+"合计"+"¥"+No*price);

                        while ("y".equals(answer)) {

System.out.print("是否继续(y/n)\n");

                        answer = input.next();

                        total = price*discount*No;

                        System.out.println("折扣:" + discount);

                        System.out.println("应付金额:" + total);

                        System.out.print("实付金额:" );


paymoney = input.nextDouble();


System.out.println("找钱:" + (paymoney-total));




       
       }
       
}
}











































  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值