0
点赞
收藏
分享

微信扫一扫

编写一个Java Application程序,文件名为 长方体.java。

言诗把酒 2022-03-19 阅读 28
java

编写一个Java Application程序,文件名为 长方体.java

目的

要求

代码

public class 长方体
{
    int length,width,height,S,L;
//初始化
    public void setBox(int l,int w,int h)
    {
        length=l;
        width=w;
        height=h;
    }
    public void setBox()
    {
        length=7;
        width=8;
        height=9;
    }
//面积
    public void getArea()
    {
        S=2*(length*width+width*height+length*height);
    }
//体积
    public void getL()
    {
        L=length*width*height;
    }
//显示
    public void showinformation()
    {
        System.out.println("length="+length);
        System.out.println("wight="+width);
        System.out.println("height="+height);
    }
    public void showarea()
    {
        System.out.println("长方体的面积为"+S);
    }
    public void showL()
    {
        System.out.println("长方体的体积为"+L);
    }

    public static void main(String[] args)
    {
    长方体 a;
    a=new 长方体();
    a.setBox(2,3,4);
    System.out.println("长方体A:");
    a.showinformation();
    a.getArea();
    a.showarea();
    a.getL();
    a.showL();

    System.out.println("长方体B:");
    长方体 b;
    b=new 长方体();
    b.length=3;
    b.height=4;
    b.width=5;
    b.showinformation();
    b.getArea();
    b.showarea();
    b.getL();
    b.showL();

    System.out.println("长方体C:");
    长方体 c;
    c=new 长方体();
    c.setBox();
    c.showinformation();
    c.getArea();
    c.showarea();
    c.getL();
    c.showL();
    }
}

运行结果

运行结果

举报

相关推荐

0 条评论