请完成相关代码,实现长方体的表面积和体积的计算
函数接口定义:
请详细参见主程序的调用方式。
裁判测试程序样例:
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.printf("%.4f",myCuboid.getArea());
System.out.println();
System.out.printf("%.4f",myCuboid.getVolume());
input.close();
}
}
输入样例:
在这里给出一组输入。例如:
3.5 2 5
输出样例:
在这里给出相应的输出。例如:
69.0000
35.0000
class Cuboid{
double l, w, h;
Cuboid(){
}
Cuboid(double l, double w, double h){
this.l = l;
this.w = w;
this.h = h;
}
public double getArea() {
return 2 * (l * w + l * h + w * h);
}
public double getVolume() {
return w * l * h;
}
}