一个计算Box体积和面积的java小程序
来源:优易学  2011-12-17 15:47:17   【优易学:中国教育考试门户网】   资料下载   IT书店

  class Box{

  double width;

  double height;

  double depth;

  public Box(double w,double h,double d){

  width=w;

  height=h;

  depth=d;

  }

  void getBox(){

  System.out.println("The width of Box is :"+width);

  System.out.println("the heigth of Box is :"+height);

  System.out.println("The depth of Box is :"+depth);

  }

  void volume(){

  System.out.println("The volume of Box is:"+(width*height*depth));

  }

  void area(){

  System.out.println("The area of Box is :"+2*(width*height+width*depth+height*depth));

  }

  }

  public class BoxDemo {

  public static void main(String args[]){

  Box box=new Box(5,2,5);

  box.getBox();

  box.volume();

  box.area();

  }

  }

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训