博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
几何面积体积_2
阅读量:6457 次
发布时间:2019-06-23

本文共 5950 字,大约阅读时间需要 19 分钟。

package pro3;public class Graphic02 {    public static void main(String[] args) {        ball ball01=new ball("red",3);        ball ball02=new ball("blue",4);        square square01=new square("red",3,4);        triangle triangle01=new triangle("blue",3,4,5);        testGraphic t1=new testGraphic(ball01,ball02);        testGraphic t2=new testGraphic(square01,triangle01);        t1.compare();        t2.printSumA();    }}class testGraphic{    private ball b1;    private ball b2;    private square s1;    private triangle t1;    public testGraphic(ball b1,ball b2){        this.b1=b1;        this.b2=b2;    }    public testGraphic(square s1,triangle t1){        this.s1=s1;        this.t1=t1;    }    public void compare(){        if(b1.graphicV()>b2.graphicV()){            System.out.println(b1.getColor()+"色的球体积"+b1.graphicV()+"大于"+b2.getColor()+"色的球的体积"+b2.graphicV());        }else{            System.out.println(b2.getColor()+"色的球体积"+b2.graphicV()+"大于"+b1.getColor()+"色的球的体积"+b1.graphicV());        }    }    public void printSumA(){        System.out.println(s1.getColor()+"色矩形和"+t1.getColor()+"色三角形面积的和:"+(s1.graphicA()+t1.graphicA()));    }}class ball{    private String color;    private double side01;    public ball(String color,double side01) {        this.setColor(color);        this.setSide01(side01);    }    public void setColor(String color){        this.color=color;    }    public void setSide01(double side01){        this.side01=side01;    }    public String getColor(){        return this.color;    }    public double getSide01(){        return this.side01;    }    public double graphicA(){        return 4*3.14*side01*side01;    }    public double graphicV(){        double v=3.14*3/4*side01*side01*side01;        return v;    }    public void print(){        System.out.println("颜色是"+this.color);    }}class comuln{    private String color;    private double side01;    private double side02;    public comuln(String color,double side01,double side02) {        this.setColor(color);        this.setSide01(side01);        this.setSide02(side02);    }    public void setColor(String color){        this.color=color;    }    public void setSide01(double side01){        this.side01=side01;    }    public void setSide02(double side02){        this.side02=side02;    }    public String getColor(){        return this.color;    }    public double getSide01(){        return this.side01;    }    public double getSide02(){        return this.side02;    }    public double graphicA(){        return 2*3.14*side01*side01+2*3.14*side01*side02;    }    public double graphicV(){        return 3.14*side01*side01*side02;    }}class cone{    private String color;    private double side01;    private double side02;    public cone(String color,double side01,double side02) {        this.setColor(color);        this.setSide01(side01);        this.setSide02(side02);    }    public void setColor(String color){        this.color=color;    }    public void setSide01(double side01){        this.side01=side01;    }    public void setSide02(double side02){        this.side02=side02;    }    public String getColor(){        return this.color;    }    public double getSide01(){        return this.side01;    }    public double getSide02(){        return this.side02;    }    public double graphicA(){        return 3.14*side01*side01+3.14*side01*java.lang.Math.sqrt(side02*side02+side01*side01);    }    public double graphicV(){        return 3.14/3*side01*side01*side02;    }}class square{    private String color;    private double side01;    private double side02;    public square(String color,double side01,double side02) {        this.setColor(color);        this.setSide01(side01);        this.setSide02(side02);    }    public void setColor(String color){        this.color=color;    }    public void setSide01(double side01){        this.side01=side01;    }    public void setSide02(double side02){        this.side02=side02;    }    public String getColor(){        return this.color;    }    public double getSide01(){        return this.side01;    }    public double getSide02(){        return this.side02;    }    public double graphicA(){        return side01*side02;    }    public double graphicL(){        return 2*(side01+side02);    }}class triangle{    private String color;    private double side01;    private double side02;    private double side03;    public triangle(String color,double side01,double side02,double side03) {        this.setColor(color);        this.setSide01(side01);        this.setSide02(side02);        this.setSide03(side03);    }    public void setColor(String color){        this.color=color;    }    public void setSide01(double side01){        this.side01=side01;    }    public void setSide02(double side02){        this.side02=side02;    }    public void setSide03(double side03){        this.side03=side03;    }    public String getColor(){        return this.color;    }    public double getSide01(){        return this.side01;    }    public double getSide02(){        return this.side02;    }    public double getSide03(){        return this.side03;    }    public double graphicA(){        return side01*(java.lang.Math.sqrt(java.lang.Math.abs(side03*side03-side01*side01))/2);    }    public double graphicL(){        return side01+side02+side03;    }}class circle{    private String color;    private double side01;    public circle(String color,double side01) {        this.setColor(color);        this.setSide01(side01);    }    public void setColor(String color){        this.color=color;    }    public void setSide01(double side01){        this.side01=side01;    }    public String getColor(){        return this.color;    }    public double getSide01(){        return this.side01;    }    public double graphicA(){        return 3.14*side01*side01;    }    public double graphicL(){        return 2*3.14*side01;    }}

 

转载于:https://www.cnblogs.com/hxtblogs/p/7591337.html

你可能感兴趣的文章
EJB2的配置
查看>>
最容易理解的对卷积(convolution)的解释
查看>>
《机器学习实战》知识点笔记目录
查看>>
Linux操作系统实时性分析
查看>>
mysql导出导入所有数据库
查看>>
[转载]数据库缓存算法思想与实现
查看>>
完美解决NC502手工sql的查询引擎排序及合计问题
查看>>
PHP+MySQL代码部署在Linux(Ubuntu)上注意事项
查看>>
Tiny语言执行环境TM机源码
查看>>
PE文件之资源讲解
查看>>
windows 7/mac编译cocos2d-x-3.2*的android工程报错
查看>>
MYSQL导入导出.sql文件(转)
查看>>
使用Elasticsearch、Logstash、Kibana与Redis(作为缓冲区)对Nginx日志进行收集(转)
查看>>
git review报错一例
查看>>
Tomcat在Linux上的安装与配置
查看>>
《信息安全系统设计基础》 课程教学
查看>>
Linux平台下使用rman进行oracle数据库迁移
查看>>
全栈工程师学习Linux技术的忠告
查看>>
iOS自定制tabbar与系统的tabbar冲突,造成第一次点击各个item图片更换选中,第二次选中部分item图片不改变...
查看>>
C# Dictionary用法总结
查看>>