JAVA超市收银台

超市收银台

public class ChaoShiSystem {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		
		String pName1 = "苹果";
		double pPricel = 5;
		String pId1 = "1001";
		
		String pName2 = "香蕉";
		double pPrice2 = 7;
		String pId2 = "1002";
		
		String pName3 = "菠萝";
		double pPrice3 = 12;
		String pId3 = "1003";
		
		double amount = 0;
		
		int totalNum = 0; //商品总数量
		double totalAmount = 0; //商品总金额
		
		System.out.println("**********超市收银台*************");
		while(true) {
			while(true) {
				System.out.println("请输入商品编号:");
				String id = input.next();
				
				
				String name = "";
				double price = 0;
				
				if(pId1.equals(id)) {
					name = pName1;
					price = pPricel;
					
				}else if(pId2.equals(id)) {
					name = pName2;
					price = pPrice2;
					
				}else if(pId3.equals(id)) {
					name = pName3;
					price = pPrice3;
				}else {
					
					System.out.println("没有此商品");
					continue;
				}
				
				System.out.println("请输入商品数量:");
				int num = input.nextInt();
				
				amount = price * num;
				System.out.println("您当前添加的商品是"+name+",单价"+price+"元,"+"金额为"+amount+"元");
				
				totalAmount += amount;
				totalNum += num;
				
				System.out.println("1继续添加商品,2退出结算, 3清空商品 ");
				int flag = 0;
				flag = input.nextInt();
				if(flag == 2) {
					break;
				}else if(flag == 3){
					totalAmount = 0;
					totalNum = 0;
					System.out.println("--------------------------");
					continue;
				}else {
					continue;
				}
					
			}
			//结算
			System.out.println("您购买了 " + totalNum + " 件商品,总金额为 " + totalAmount + " 元");
			while(true) {
				System.out.println("请输入付款金额:");
				double money = input.nextDouble();
				if(money >= totalAmount) {
					System.out.println("您付款"+money+"元,找零"+ (money - totalAmount) +"元");
					System.out.println("欢迎下次光临!");
					break;
					
				}else {
					System.out.println("金额不够,请重新付款");
					continue;
				}
				
			}
			System.out.println("--------------------------");
		}
	}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值