import java.util.Scanner;
public class work6{
public static void main(String[] args){
System.out.println("********************************************");
System.out.println("请选择购买的商品编号:");
System.out.println("1.T恤tt2.网球鞋t3.网球拍");
System.out.println("********************************************");
Scanner sc=new Scanner(System.in);
String flag="x";
int pId = 0;
int pNum = 0;
double tPrice = 245.0;
double wqxPrice = 570.0;
double wqpPrice = 320.0;
double oneTotalPrice = 0;
double TotalPrice = 0;
while ("x".equals(flag)){
System.out.println();
System.out.print("请输入商品编号;");
pId = sc.nextInt();
if (pId !=1 && pId !=2 && pId!=3){
System.out.println("抱歉您输入的商品不存在请重新输入");
continue;
}
System.out.print("请输入购买数量:");
pNum = sc.nextInt();
switch(pId){
case 1:
oneTotalPrice = pNum * tPrice;
System.out.println("T恤¥" + tPrice + "t数量" + pNum + "t合计¥" + oneTotalPrice);
TotalPrice =+ oneTotalPrice;
oneTotalPrice = 0;
break;
case 2:
oneTotalPrice = pNum * wqpPrice;
System.out.println("网球拍¥" + tPrice + "t数量" + pNum + "t合计¥" + oneTotalPrice);
TotalPrice += oneTotalPrice;
oneTotalPrice = 0;
break;
case 3:
oneTotalPrice = pNum * wqxPrice;
System.out.println("网球鞋¥" + tPrice + "t数量" + pNum + "t合计¥" + oneTotalPrice);
TotalPrice += oneTotalPrice;
oneTotalPrice = 0;
break;
}
System.out.println("是否继续(y/n):");
flag = sc.next();
System.out.println();
System.out.print("折扣:");
double zk = sc.nextDouble();
double yf = TotalPrice * zk;
System.out.print("应付金额"+ yf);
System.out.println();
System.out.print("实付金额");
Double sf = sc.nextDouble();
if (yf > sf){
System.out.print("您输入的金额小于应付金额,请重新输入");
sf = sc.nextDouble();
}
System.out.print("找钱"+(sf - yf));
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)