广州打的费用计算公式

来源:互联网 发布:手机淘宝有签到领金币 编辑:程序博客网 时间:2024/05/01 18:30

 

calcFeeOfTaxi()为计算广州打的费用的方法,参考了百度地图打的费用。


// 计算打的费用private int calcFeeOfTaxi(int distance) {int result = 10; // 起步价,起租里程int initDistance = 2500; //  起租里程2.5公里float chargingPrice = 2.6f; // 超过起租里程2.5公里的价格:2.6元/公里float chargingPriceEmpty = 3.9f; // 超过35公里,自动计算50%空驶费,价格:3.9元/公里if (distance > 35000) {int fee = calcFee(35000 - initDistance, chargingPrice); // 正常费用int feeEmpty = calcFee(distance - 35000, chargingPriceEmpty); // 超过35公里,计算空驶费result = 10 + fee + feeEmpty;// 起步价 + 正常费用 + 空驶费} else {if (distance > initDistance) {int fee = calcFee(distance - initDistance, chargingPrice); // 正常费用result = 10 + fee;// 起步价 + 正常费用} else {result = 10;// 起步价 }}return result;}// 计算费用private int calcFee(int distance, float price) {int result = 0;float chargingDis = distance / 1000.0f; // 公里float fee = chargingDis * price; // 价格单位:元/公里if ((int) fee < fee) {result = (int) fee + 1;} else {result = (int) fee;}return result;}



原创粉丝点击