Untitled
unknown
java
3 years ago
1.4 kB
4
Indexable
public class Cylinder extends Circle {
protected static final double PI = 3.14;
private double height;
Cylinder() {
}
public Cylinder(double radius) {
super(radius);
}
Cylinder(double radius, double height) {
super(radius);
this.height = height;
}
Cylinder(double radius, double height, String color) {
super(radius, color);
this.height = height;
}
/**
*.
*/
public static void main(String[] args) {
Circle circle = new Circle(4.0, "blue");
Cylinder cylinder = new Cylinder(4.0, 4.0, "red");
System.out.println(circle.toString());
System.out.println(cylinder.toString());
System.out.println(cylinder.height);
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
/**
*.
*/
public double getVolume() {
return super.getArea() * height;
}
/**
*.
*/
@Override
public String toString() {
return String.format("Cylinder[%s],height=%f", super.toString(), height);
}
/**
*.
*/
@Override
public double getArea() {
return super.getArea() * 2 + super.getRadius() * 2 * PI * 2;
}
}
Editor is loading...