JAVA计算木材公式算法

1、 检尺径自4~12厘米的小径原木材积由公式 V=0.7854L(D+0.45L+0.2)2÷10000确定。
2、 检尺径自14厘米以上的原木材积由公式 V=0.7854L[D+0.5L+0.005L2+0.000125L(14-L)2×(D-10)]2÷10000确定。两式中:V---材积,立方米;L---检尺长,米;D---检尺径,厘米。

package com.github.pig.auth;

import java.math.BigDecimal;

public class ExpressionUtil {

	public static double v1(double L, double D) {
		System.out.println("长度:"+L+"直径:"+D);
		return 0.7854 * L * Math.pow((D + 0.45 * L + 0.2), 2) / 10000.0;
	}

	public static double v2(double L, double D) {
		return 0.7854
				* L
				*Math.pow((D + 0.5 * L + 0.005 *Math.pow( L, 2)  + 0.000125 * L * Math.pow((14 - L), 2) 
						* (D - 10)), 2)  / 10000;
	}

	public static double calculation(double L, double D) {
		
		
		double result = 0.0;
		if (D >= 4 && D<= 12) {
			result = v1(L, D);
		}
		if (D > 14) {
			result = v2(L, D);
		}
		BigDecimal b = new BigDecimal(result);
		double f1 = b.setScale(4, BigDecimal.ROUND_FLOOR).doubleValue();
		return f1;
	}

	public static void main(String[] args) {
      System.out.println(calculation(2.6,22));
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值