码迷,mamicode.com
首页 > 其他好文 > 详细

购买商品

时间:2020-03-17 15:37:55      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:put   输入   new   util   网球拍   equal   bre   支付   cas   

import java.util.Scanner;


public class bba {

/**
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//商品清单
System.out.println("*******************************************");
System.out.println("请选择购买的商品编号:");
System.out.println("1.T 恤 2.网球鞋 3.网球拍");
System.out.println("*******************************************");
String re = "y";
double total = 0; //总金额
while(re.equals("y")){
System.out.print("请输入商品编号:");
int no = input.nextInt();
System.out.print("请输入购买数量:");
int count = input.nextInt();
String name = "未知";
double price = 0;
switch(no){
case 1:
name = "T 恤";
price = 125;
break;
case 2:
name = "网球鞋";
price = 245;
break;
case 3:
name = "网球拍";
price = 420;
break;
}
double sum = price*count; //合计
total = total + sum;
System.out.println(name+"\t"+"¥"+price+"\t"+count+"¥"+sum);
System.out.print("是否继续(y/n):");
re = input.next();
}
System.out.println("\n折扣:0.8");
double sz = (total*0.8);
System.out.println("应付金额:"+sz);
System.out.print("实付金额:");
double money = input.nextDouble();
while(money<sz){
System.out.print("金额不足,请重新支付:");
money = input.nextDouble();
}
System.out.println("找钱:"+(money-sz));

}

}

 

购买商品

标签:put   输入   new   util   网球拍   equal   bre   支付   cas   

原文地址:https://www.cnblogs.com/aaaaaa6699/p/12510915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!