package com.task04;
import javax.swing.*;
public class ComputePriceIF {
public static void mian(String[] args) {
int c,s=0;
double p=0,w=0,d,f;
p=Double.parseDouble(JOptionPane.showInputDialog("请输入运输公司的运输单价",new Double(p)));
w=Double.pareeDouble(JOptionPane.showInputDialog("请输入要运输的货物的重量",new Double(w)));
s=Integer.parseInt(JOptionPane.showInputDialog("请输入运输的距离",new Integer(s)));
if(s>=3000)c=12;
else c=s/250;
if(c<1)d=0;
else if(c<2)d=0.02;
else if(c<4)d=0.05;
else if(c<8)d=0.08;
else if(c<12)d=0.1;
else d=0.15;
f=p*w*s*(1-d);
System.out.println("运输公司的运输单价为"+p);
System.out.println("该次运输的货物重量为"+w);
System.out.println("该次运输的运输距离为"+s);
System.out.println("该次运输的总运费为"+f);
}
}
1.main方法名字写错了,是main,不是mian
2.第9号的pareeDouble写错了,是parse,不是paree
3.最后的结果想保留2位小数的话,可以写成
System.out.println("该次运输的总运费为"+String.format("%.2f",f));
4.在实际开发中,有小数点时Double不常用,BigDecimal最佳选择,如果只是做做练习,用Double也行
就是双精度浮点型
主要是8,9,10行问题
都改成bigdecimal 这个格式