import java.util.*;
public class guowu{
public static void main(String []args){
System.out.println("********************************************");
System.out.println("请选择购买商品的编号:");
System.out.println("1.T恤\t\t2.网球鞋\t3.网球拍");
System.out.println("********************************************");
Scanner sc = new Scanner(System.in); //创建对象
String jixv ="y"; //定义是否继续购买
int spb =0; //定义储存商品的编号的变量
int sps =0; //定义储存商品的数量的变量
double tixu = 245.0; //定义T恤价格
double wangx = 570.0; //定义网球鞋价格
double wangq = 320.0; //定义网球拍价格
double spd =0; //定义每次购买商品的总价
double spz =0; //定义购买商品的总价
while("y".equals(jixv)){
System.out.println(); //为了运算时画面精美
System.out.print("请输入商品的编号:");
spb =sc.nextInt(); //接受数据
System.out.print("请输入购买数量:");
sps =sc.nextInt(); //接受数据
switch(spb){
case 1:
spd = tixu * sps;
System.out.println("T恤"+"¥"+tixu+"\t"+"数量:"+sps+"\t"+"合计"+"¥"+spd);
spz += spd;
spd = 0; //数据清0
break;
case 2:
spd = wangx * sps;
System.out.println("网球鞋"+"¥"+wangx+"\t"+"数量:"+sps+"\t"+"合计"+"¥"+spd);
spz += spd;
spd = 0;
break;
case 3:
spd = wangq * sps;
System.out.println("网球拍"+"¥"+wangq+"\t"+"数量:"+sps+"\t"+"合计"+"¥"+spd);
spz += spd;
spd = 0;
break;
}
System.out.print("是否继续(y/n):");
jixv = sc.next();
}
System.out.println(); //为了运算时画面精美
System.out.print("折扣:");
double zk = sc.nextDouble();
spz *= zk;
System.out.println("应付金额:"+spz);
System.out.print("实付金额:");
double sf = sc.nextDouble();
if(sf < spz){
System.out.print("您输入的金额小于应付金额,请重新输入:");
sf = sc.nextDouble();
}
System.out.println("找钱:"+(sf-spz));
}
}
相关文章
- 03-15力扣503. 下一个更大元素 II(单调栈、拉长循环数组,遍历两次)
- 03-15leetcode 503 循环数组 单调栈
- 03-15【Android】Error obtaining UI hierarchyError while obtaining UI hierarchy XML file: com.android...
- 03-15jsfor循环打印金字塔
- 03-15《Python从入门到实践》--第七章 while循环 课后练习
- 03-15获取数值型数组中大于60的元素个数,给数值型数组中不足60分的加20分。(数组,for循环,if条件判断语句)
- 03-15when ‘while‘ meets the ‘function‘
- 03-15sass css样式:@for循环、样式变量与#{} 变量插值
- 03-15SqlServer循环读取配置
- 03-15RocketMq发送消息出现com.alibaba.rocketmq.client.exception.MQBrokerException: CODE: 2 DESC: [TIMEOUT_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: 201ms, size of queue: 1