作业帮 > 综合 > 作业

接收三个商品价格,只要有一种商品价格大于50元,或者三种商品价格的综合大于100元,则打折,折扣率为0.15;根据用户的

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/07/11 12:28:48
接收三个商品价格,只要有一种商品价格大于50元,或者三种商品价格的综合大于100元,则打折,折扣率为0.15;根据用户的输入,求得该用户应该付款多少元,并且输出相应的折扣价和折扣后应付的价格.
本人新手 求组高手帮忙用JAVA
接收三个商品价格,只要有一种商品价格大于50元,或者三种商品价格的综合大于100元,则打折,折扣率为0.15;根据用户的
public static void main(String[]argv){
double price1=0;
double price2=0;
double price3=0;
int product1=0;
int product2=0;
int product3=0;

java.util.Scanner sc=new java.util.Scanner(System.in);
System.out.println("请输入3个价格:");
price1=sc.nextDouble();
price2=sc.nextDouble();
price3=sc.nextDouble();

System.out.println("请输入3种产品的数量:");
product1=sc.nextInt();
product2=sc.nextInt();
product3=sc.nextInt();

System.out.println("单价1="+price1);
System.out.println("单价2="+price2);
System.out.println("单价3="+price3);
if( (price1>50 || price2>50 || price3>50) || (price1+price2+price2>100)){
price1=price1 * (1.0-0.15);
price2=price2 * (1.0-0.15);
price3=price3 * (1.0-0.15);
}
double pay1=price1*product1;
double pay2=price2*product2;
double pay3=price3*product3;

System.out.println("单价1="+price1+",数量1:"+product1+",支付:"+pay1);
System.out.println("单价2="+price2+",数量2:"+product2+",支付:"+pay2);
System.out.println("单价3="+price3+",数量3:"+product3+",支付:"+pay3);
System.out.println("总支付:"+(pay1+pay2+pay3));
}
再问: price1=price1*(1.0-0.15) 为什么是1.0-0.15呢?
再答: 打85折,优惠部分是15%,所以剩下的是(1.0-0.15)