Java面向对象编程求三角形面积,周长;梯形面积;圆形周长面积

package pcj.com;
class Tangle {
    int a, b, c;

    Tangle(int a, int b, int c) {
        this.a=a;
        this.b=b;
        this.c=c;
    }
    public double triangleArea(){
        float p=(a+b+c)/2f;
        float s1=(float)Math.sqrt(p*(p-a)*(p-b)*(p-c));
        return s1;
    }
    public int triangleGrith() {
        return a + b + c;
    }


    void display(){
        System.out.println("三角形面积:"+this.triangleArea());
    }
    void display_01(){
        System.out.println("三角形周长:"+this.triangleGrith());
    }


}
class Ladder{
    int d1,d2,h;
    Ladder(int d1,int d2,int h){
        this.d1=d1;
        this.d2=d2;
        this.h=h;
    }
    public double LadderArea(){
        float s2=((d1+d2)*h)/2f;
        return s2;
    }
    void display_02(){
        System.out.println("梯形的面积是:"+this.LadderArea());
    }
}

class Circle{
    int r;
    Circle(int r){
        this.r=r;
    }
    public double circleArea(){
        float s3=(float) 3.14*r*r;
        return s3;
    }
    public double circleGirth(){
        double c=(double) 2*3.14*r;
        return c;
    }
    void display_03(){
        System.out.println("圆形的面积是:"+this.circleArea());
    }
    void display_04(){
        System.out.println("圆形的周长是:"+this.circleGirth());
    }
}
public class Graph {
    public static void main (String[] args){
        Tangle t1=new Tangle(3,4,5);
        t1.display();
        t1.display_01();
        Ladder l1=new Ladder(3,5,6);
        l1.display_02();
        Circle c1=new Circle(4);
        c1.display_03();
        c1.display_04();
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值