62,614
社区成员
发帖
与我相关
我的任务
分享
class point {
float x, y;
public point(float a, float b) {
x = a;
y = b;
}
public void setPoint(float x, float y) {
this.x = x;
this.y = y;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
}
class circle extends point {
protected float radius;
// final float PI=3.14;
public circle(float a, float b, float r) {
super(a, b);
radius = r;
}
public void setCircle(float r) {
radius = r;
}
float getRadius() {
return radius;
}
double area() {
return 3.14 * radius * radius;
}
}
class cylinder extends circle {
float heigh;
public cylinder(float a, float b, float r, float h) {
super(a, b, r);
heigh = h;
}
void setHeigh(float h) {
heigh = h;
}
float getHeigh() {
return heigh;
}
double volume() {
return super.area() * heigh;
}
public static void main(String[] args) {
cylinder cylinder1 = new cylinder(3.5F, 6.4F, 5.2F, 10F);
cylinder cylinder2 = new cylinder(3.7F, 6.5F, 5.3F, 11F);
cylinder cylinder3 = new cylinder(3.8F, 6.6F, 5.4F, 12F);
System.out.println(cylinder1.getX() + " " + cylinder1.getY() + " "
+ cylinder1.radius + " " + cylinder1.heigh + " "
+ cylinder1.volume());
System.out.println(cylinder2.getX() + " " + cylinder2.getY() + " "
+ cylinder2.radius + " " + cylinder2.heigh + " "
+ cylinder2.volume());
System.out.println(cylinder3.getX() + " " + cylinder3.getY() + " "
+ cylinder3.radius + " " + cylinder3.heigh + " "
+ cylinder3.volume());
}
}