代码拉取完成,页面将自动刷新
import java.util.Scanner;
public class Code010 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name = "";
double price = 0.0;
int goodsNo = 0;
int amount = 0;
double discount = 0.8;
double total = 0.0;
double money = 0.0;
System.out.println("MyShopping 管理系统 > 购物结算\n");
System.out.println("*************************************************** **");
System.out.println("请选择购买的商品编号:");
System.out.println("1.T 恤\t\t2.网球鞋\t\t3.网球拍");
System.out.println("*************************************************** **\n");
String answer = "y";
while("y".equals(answer)){
System.out.print("请输入商品编号:");
goodsNo = input.nextInt();
System.out.print("请输入购买数量:");
amount = input.nextInt();
switch(goodsNo){
case 1:
name = "T 恤";
price = 245.0;
break;
case 2:
name = "网球鞋";
price = 570.0;
break;
case 3:
name = "网球拍";
price =320.0;
break;
}
total = price * amount;
System.out.println(name + "¥" + price + "\t" + "数量" + amount + "\t合计¥" + total);
System.out.println("是否继续(y/n)");
answer = input.next();
System.out.println();
money += total;
}
System.out.println("折扣:" + discount);
System.out.println("应付金额:" + (money * discount));
System.out.print("实付金额:");
double payment = input.nextDouble();
System.out.println("找钱:" + (payment - money * discount));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。