import java.util.Scanner;
public class Demo15{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double tPrice = 245; //T恤价格
double qxPrice = 570; //球鞋价格
double qpPrice = 150; //球拍价格
double sumPrice = 0; //单品总价格
double price = 0; //最终总价格
String tName = "T恤";
String qxName = "网球鞋";
String qpName = "网球拍";
String name = "";
System.out.println("我行我素购物管理系统 > 购物结算\n\n");
System.out.println("******************************************");
System.out.println("请选择购买的商品编号:");
System.out.println("1、T恤\t\t"+tPrice+"\n2、网球鞋\t"+qxPrice+"\n3、网球拍\t"+qpPrice);
System.out.println("******************************************");
System.out.println("");
boolean b = true;
do{
System.out.println("");
System.out.print("请输入商品编号:");
int id = sc.nextInt();
System.out.print("\n请输入购买数量:");
int count = sc.nextInt();
//判断用户此次购买的是哪种商品
if(id==1){
sumPrice = tPrice * count;
name = tName;
}else if(id==2){
sumPrice = qxPrice * count;
name = qxName;
}else{
sumPrice = qpPrice * count;
name = qpName;
}
price = price + sumPrice;//统计最终金额
System.out.println(name+"\t¥"+(sumPrice/count)+"\t¥"+sumPrice);
System.out.print("是否继续(y/n):");
String flag = sc.next();
switch(flag){
case "n":
b = false;
}
}while(b);
System.out.println("折扣0.8");
System.out.println("金额总计:"+price * 0.8);
System.out.print("实际交费:");
double realPrice = sc.nextDouble();
if(realPrice>=(price*0.8)){
System.out.println("找钱:"+(realPrice-price * 0.8));
}else{
System.out.println("您付的金额不足!请重新交费。");
}
}
}