6-2 设计一个长方体类Cuboid分数 20作者 lamda单位 山东科技大学 要求:设计一个名为Cuboid的类表示长方体。这个类包括三个名为length、width和height 的d

6-2 设计一个长方体类Cuboid

分数 20

全屏浏览

切换布局

作者 lamda

单位 山东科技大学

要求:设计一个名为Cuboid的类表示长方体。这个类包括三个名为length、width和height 的double型数据域,它们分别表示长方体的长、宽和高。
一个无参构造方法, length、width、height的默认值都为1。 一个为length、width、height指定值的构造方法。
一个名为getArea()的方法返回这个长方体的表面积。 一个名为getVolume()的方法返回这个长方体的体积。

函数接口定义:

 

public double getArea(); public double getVolume();

裁判测试程序样例:

 

import java.util.Scanner; /* 你的代码将被嵌入到这里 */ public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); double l = input.nextDouble(); double w = input.nextDouble(); double h = input.nextDouble(); Cuboid myCuboid = new Cuboid(l, w, h); System.out.println(myCuboid.getArea()); System.out.println(myCuboid.getVolume()); input.close(); } }

输入样例:

3.5 2 5

输出样例:

69.0
35.0

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

   class Cuboid{
	   double length,width,height;

	public Cuboid() {
		
		length=1;
		width=1;
		height=1;
	}

	public Cuboid(double length, double width,  double height) {
		
		this.length = length;
		this.width = width;
		this.height = height;
	}
	

  public double getArea(){
	  return 2*(length*width+width*height+length*height);
	  
	  }
  public double  getVolume() {
	  return length*width*height;
	
}
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值