package 圆;
public class circle {
private double Radius;
public double getRadius(){
return Radius;
};
public void setRadius(double r) {
Radius= r;
}
public circle(double r){
Radius=r;
}
public double getPerimeter(){//底圆周长
return 2 * Math.PI * Radius;
}
public double getArea(){//面积
return Math.PI *Radius *Radius;
}
public void show( ){
System.out.println("圆的半径: " +getRadius());
System.out.println("圆的面积: " +getArea());
System.out.println("Circle circumference: " +getPerimeter());
}
}
package circle;
public class yuanzhu extends circle {//Cylinder class inherits circle class
private double height;
public double getheight() {
return height;
}
public void setheight(double h) {
height = h;
}
public yuanzhu(double r,double h){
super(r);
height=h;
}
public double getVolume(){//Get the volume
return getArea() * height;
}
public void showVolume( ){
System.out.println("Volume of cylinder:" +getVolume());
}
}
package circle;
public class MAIN {
public static void main(String[] args) {
circle d1 = new circle(2);//The radius is initialized to 3
d1.show( );
yuanzhu d2 =new yuanzhu(3,6);//The height is initialized to 6
d2.showVolume();
}
}