所以我有这两个类叫做装运和保险,一个计算运费的价格,另一个加上保险。出货逻辑工作正常但由于某种原因保险类中的if语句不起作用我不知道发生了什么。保险费用的输出总是2.45。它为什么这样做?
发货类:
package theshipment;
public class Shipment extends Main {
protected double weight = Double.parseDouble(savedArgs[1]);
protected double shippingCost;
protected double methodCost;
protected String method = savedArgs[2];
public void calculateShippingCost(){
if (weight<=10||weight>=1){
if (method.equalsIgnoreCase("T"))
methodCost = weight * 3.00;
else if (method.equalsIgnoreCase("A"))
methodCost = weight * 4.00;
else if (method.equalsIgnoreCase("M"))
methodCost = weight * 2.00;
else{}
}else if (weight<=20||weight>=10.1){
if (method.equalsIgnoreCase("T"))
methodCost = weight * 2.45;
else if (method.equalsIgnoreCase("A"))
methodCost = weight * 3.00;
else if (method.equalsIgnoreCase("M"))
methodCost = weight * 1.75;
else{}
}else if (weight>20){
if (method.equalsIgnoreCase("T"))
methodCost = weight * 1.95;
else if (method.equalsIgnoreCase("A"))
methodCost = weight * 2.50;
else if (method.equalsIgnoreCase("M"))
methodCost = weight * 1.55;
else{}
}else{}
}
}
保险类:
package theshipment;
public class Insurance extends Shipment{
private void calculateInsurance(){
if (methodCost<=10.0||methodCost>=0.0)
shippingCost = methodCost + 2.45;
else if(methodCost<=30.0||methodCost>=10.1)
shippingCost = methodCost + 3.95;
else if(methodCost>=30.01)
shippingCost = methodCost + 5.55;
else{}
}
public void run(){
calculateShippingCost();
calculateInsurance();
}
public String displayOrder(){
return ("Method cost: " + methodCost + " " + "Insurance cost: " +
(shippingCost-methodCost) + " Total shipping cost: " + shippingCost);
}
}
答案 0 :(得分:10)
methodCost<=10.0||methodCost>=0.0
这意味着当methodCost
大于0 OR 小于10
我相信您希望范围不是所有数字都将其更改为methodCost<=10.0 && methodCost>=0.0