前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Java工具集-数学(圆柱体,椎体工具类)

Java工具集-数学(圆柱体,椎体工具类)

作者头像
cwl_java
发布2019-10-26 21:18:34
3030
发布2019-10-26 21:18:34
举报
文章被收录于专栏:cwl_Java

简单工具类

写作初衷:由于日常开发经常需要用到很多工具类,经常根据需求自己写也比较麻烦 网上好了一些工具类例如commom.lang3或者hutool或者Jodd这样的开源工具,但是 发现他们之中虽然设计不错,但是如果我想要使用,就必须要引入依赖并且去维护依赖,有些 甚至会有存在版本编译不通过问题,故此想要写作一个每个类都可以作为独立工具类使用 每个使用者只需要复制该类,到任何项目当中都可以使用,所以需要尊从以下两个原则才能 做到.在此诚邀各位大佬参与.可以把各自用过的工具,整合成只依赖JDK,每个类都能够单独 使用的工具.每个人当遇到业务需求需要使用的时候,只需要到这里单独拷贝一个即可使用. 抛弃传统的需要引入依赖的烦恼.让大家一起来解决你所面临的业务问题吧!

介绍

遵从两大原则

  • 1.绝不依赖JDK以外的源码
  • 2.牺牲代码复用性,每个类都必须是单独的组件,绝不互相引用,做到完全解耦
代码语言:javascript
复制
package *;

import java.text.DecimalFormat;

/**
 * @program: simple_tools
 * @description: 圆柱体,椎体工具类
 * @author: ChenWenLong
 * @create: 2019-06-03 17:59
 **/
public class CylinderUtils {

    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 : [r, highth]
     * @return : boolean
     * @author : cwl
     * @date : 2019/6/3 18:01
     */
    public static boolean isCylinder(double r,double highth){
        if(r == 0 || highth == 0){
            throw new IllegalArgumentException("This isn't Cylinder");
        }
        return true;
    }

    /**
     * 功能描述:
     * 〈获取圆柱体表面积〉
     *
     * @params : [r, highth]
     * @return : double
     * @author : cwl
     * @date : 2019/6/3 18:03
     */
    public static double getArea(double r,double highth){
        isCylinder(r,highth);
        return roundValue(2*Math.PI*r*highth);
    }

    /**
     * 功能描述:
     * 〈获取圆柱体体积〉
     *
     * @params : [r, highth]
     * @return : double
     * @author : cwl
     * @date : 2019/6/3 18:06
     */
    public static double getVolume(double r,double highth){
        isCylinder(r,highth);
        return calculateVolume(r,highth,false);
    }

    /**
     * 功能描述:
     * 〈计算是圆柱体还是圆锥体的体积〉
     *
     * @params : [r, highth, isCircularCone]
     * @return : double
     * @author : cwl
     * @date : 2019/6/4 10:56
     */
    private static double calculateVolume(double r, double highth, boolean isCircularCone) {
        if(isCircularCone){
            double proportion = 1 / 3;
            return roundValue(proportion*r*r*Math.PI*highth);
        }
        return roundValue(r*r*Math.PI*highth);
    }

    /**
     * 功能描述:
     * 〈获取圆柱体横截面积〉
     *
     * @params : [r, highth]
     * @return : double
     * @author : cwl
     * @date : 2019/6/4 10:10
     */
    public static double getCAS(double r,double highth){
        isCylinder(r,highth);
        return roundValue(2*r*highth);
    }

    /**
     * 功能描述:
     * 〈获取圆锥体的体积〉
     *
     * @params : [r, highth]
     * @return : double
     * @author : cwl
     * @date : 2019/6/4 10:36
     */
    public static double getVolume(double r,double highth,boolean isCircularCone){
        isCylinder(r,highth);
        return calculateVolume(r,highth,isCircularCone);
    }

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/10/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简单工具类
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档