首页 > 解决方案 > 修改 calculateFittingCost() 方法,使其将可变劳动力成本乘以适当的成本乘数

问题描述

所以我正在创建一个程序来计算地毯的供应和安装成本。

我正在努力修改以下代码,以便将可变劳动力成本乘以适当的成本乘数。

private double calculateFittingCost (int length, int width, double price)
    return (length * width) * labourCharge; 
}  

这是关于成本乘数的部分

public double costMultiplier() {
    double multiplier = 1.0;
    if (postCode != null) {
        if (postCode.toUpperCase().startsWith("WC1A") || postCode.toUpperCase().startsWith("EC1A")) {
            multiplier = 1.2;
        }
    }
    return multiplier;
}

标签: javabluej

解决方案


假设你的公式是:

拟合成本 = l * w * unitPrice * 乘数

private double fittingCost(double unitAreaPrice, double length,double width, String postalCode ){
    return unitAreaPrice * length * width * computeMultiplier(postalCode);
}

private double computeMultiplier(final String postalCode){
    final double LOW = 1.0;
    final double HIGH = 1.2;
    if (postalCode.toUpperCase().startsWith("WC1A") || postalCode.toUpperCase().startsWith("EC1A")) {
        return HIGH;
    }
    return LOW;
}

推荐阅读