class Cuboid {
double a;
double b;
double h;
double area;
public Cuboid(double a, double b,double h){
this.a = a;
this.b = b;
this.h = h;
}
public Cuboid() {
// TODO Auto-generated constructor stub
}
double Area(){
area=a*b*h;
return area;
}
}
public class Test67{
public static void main(String args[]){
Cuboid cuboid = new Cuboid();
double a=12.5,b=5.2,h=2.5;
Cuboid.Cuboid(a,b,h);
System.out.println("长方提体的体积是:"+cuboid.Area());
}
}
这是题目:
1. 编程扩展下面的矩形类(Rect)为长方体类(Cuboid),要求增加高度(h)属性,并求出长方体的体积(Volume)。
public class Rect {
double a;
double b;
public Rect(double a, double b){
this.a = a;
this.b = b;
}
public double Area(){
return a * b;
}
}
Its_forever
相关分类