java做求立方体,Java工具集-数学(立方体操作工具类)

package *;

import java.text.DecimalFormat;

/**

* @program: simple_tools

* @description: 立方体操作工具类

* @author: ChenWenLong

* @create: 2019-06-03 16:58

**/

public class CuboidUtils {

public static final DecimalFormat ROUNDING_OFF = new DecimalFormat("#.00");

/**

* 功能描述:

* 〈获取四舍五入的结果值,并且取得绝对值,解决负数情况〉

*

* @params : [value]

* @return : double

* @author : cwl

* @date : 2019/6/3 15:50

*/

public static double roundValue(double value){

return Math.abs(Double.valueOf(ROUNDING_OFF.format(value)));

}

/**

* 功能描述:

* 〈判断是否是立方体〉

*

* @params : [length, wideth, highth]

* @return : boolean

* @author : cwl

* @date : 2019/6/3 17:01

*/

public static boolean isCuboid(double length,double wideth,double highth){

if(length == 0 || wideth == 0 || highth == 0){

return false;

}

return true;

}

/**

* 功能描述:

* 〈获取立方体周长,长宽高各不相同情况〉

*

* @params : [length, wideth, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:00

*/

public static double getPerimeter(double length,double wideth,double highth){

if(isCuboid(length,wideth,highth)){

return roundValue(4*(highth+length+wideth));

}

return 0;

}

/**

* 功能描述:

* 〈获取立方体周长,有两面是正方形情况〉

*

* @params : [side, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:05

*/

public static double getPerimeter(double side,double highth){

if(side == 0 || highth == 0){

throw new IllegalArgumentException("This isn't Cuboid");

}

return roundValue(side*8+highth*4);

}

/**

* 功能描述:

* 〈获取正方体周长〉

*

* @params : [side]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:26

*/

public static double getPerimeter(double side){

return roundValue(side*12);

}

/**

* 功能描述:

* 〈获取立方体的面积〉

*

* @params : [length, wideth, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:27

*/

public static double getArea(double length,double wideth,double highth){

if(isCuboid(length,wideth,highth)){

double xArea = length * wideth * 2;

double yArea = length * highth * 2;

double zArea = wideth * highth * 2;

return roundValue(xArea + yArea + zArea);

}

return 0;

}

/**

* 功能描述:

* 〈获取立方体面积,有两面是正方形情况〉

*

* @params : [side, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:30

*/

public static double getArea(double side,double highth){

if(side == 0 || highth == 0){

throw new IllegalArgumentException("This isn't Cuboid");

}

double result = side * side * 2 + side * highth * 4;

return roundValue(result);

}

/**

* 功能描述:

* 〈获取正方体面积〉

*

* @params : [side, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:30

*/

public static double getArea(double side){

return roundValue(side*side*6);

}

/**

* 功能描述:

* 〈获取立方体体积〉

*

* @params : [length, wideth, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:35

*/

public static double getVolume(double length,double wideth,double highth){

return roundValue(length*wideth*highth);

}

/**

* 功能描述:

* 〈获取立方体体积,有两面是正方形情况〉

*

* @params : [side, highth]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:36

*/

public static double getVolume(double side,double highth){

return roundValue(side*side*highth);

}

/**

* 功能描述:

* 〈获取正方体体积〉

*

* @params : [side]

* @return : double

* @author : cwl

* @date : 2019/6/3 17:36

*/

public static double getVolume(double side){

return roundValue(side*side*side);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值