package top.qaqaq.java.P268;
public class Circle {
private double radius;// 半径
public Circle() {
radius = 1.0;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
//返回圆的面积
public double findArea() {
return Math.PI * radius * radius;
}
}
package top.qaqaq.java.P268;
public class Cylinder extends Circle {
private double length;// 高
public Cylinder() {
length = 1.0;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
//返回圆柱的体积
public double findVolume() {
// return Math.PI * getRadius() * getRadius() * getLength();
return findArea() * getLength();
}
}
package top.qaqaq.java.P268;
public class CylinderTest {
public static void main(String[] args) {
Cylinder cy = new Cylinder();
cy.setRadius(2.1);
cy.setLength(3.4);
double volume = cy.findVolume();
System.out.println("圆柱的体积为:" + volume);
double area = cy.findArea();
System.out.println("底面圆的面积:" + area);
}
}