用java求梯形面积

package 求梯形面积;

public class Lader {
    double height;  //高度
    double above;   //上底
    static double bottom;  //(类变量)下底
    void setheight(double h){  //设置高度
        height=h;
    }
    double getHeight(){   //获取高度
        return height;
    }
    void setAbove(double b){  //设置上底
        above=b;
    }
    double getAbove(){   //获取上底
        return above;
    }
    void setBottom(double n){  //设置下底
        bottom=n;
    }
    double getBottom(){   //获取下底
        return bottom;
    }
    double getArea(){    //求面积
        double area=(above+bottom)*height/2;
        return area;
    }

}

package 求梯形面积;

public class Main {
    public static void main(String args[]){
        Lader.bottom=50;
        Lader lader1=new Lader();
        lader1.height=20;
        lader1.above=10;
        Lader lader2=new Lader();
        lader2.above=30;
        lader2.height=40;
        double s1=lader1.getArea();
        double s2=lader2.getArea();
        System.out.println("s1的面积"+s1+"\ns2的面积"+s2);
    }
}

你可能感兴趣的:(java,开发语言)