A商店准备在今年夏天开始出售西瓜西瓜的售价如下,20斤以上的每斤0.85元;重于15斤轻于等于20斤的,每斤0.90元;重于10斤轻于等于15斤的,每斤0.95元;重于5斤轻于等于10斤的,每斤1.00元;轻于或等于5斤的,每斤1.05元。现在为了知道商店是否会盈利要求A公司帮忙设计一个输入西瓜的重量和顾客所付钱数,输出应付货款和应找钱数。
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("输入西瓜的重量:");
Scanner sc = new Scanner(System.in);
double zhongliang = sc.nextDouble();
System.out.println("请输入顾客所付钱数:");
double m = sc.nextDouble();
double qian = money(zhongliang);
double zhaoqian = m-Double.parseDouble(String.format("%.2f", qian));
if(zhaoqian <=0) {
double zaifuqian = zhaoqian * -1;
System.out.println("应付货款"+qian+"元,还需再付"+zaifuqian+"元");
}else {
System.out.println("应付"+qian+"元,应找"+zhaoqian+"元");
}
}
public static double money(double zhongliang) {
if(zhongliang <=5) {
return zhongliang*1.05;
}else if(zhongliang <=10 ) {
return zhongliang*1;
}else if(zhongliang <=15) {
return zhongliang*0.95;
}else if(zhongliang <=20) {
return zhongliang*0.9;
}else {
return zhongliang*0.85;
}
}