package 关;
import java.util.Scanner;
public class Circle1 {
private double radius;//用于存放圆的半径;
public Circle1 ()// 将半径设为0
{
radius = 0;
}
public Circle1(double r){// 创建Circle对象时将半径初始化为r.
radius = r;
}
public Double getArea1()//获得圆的面积
{
return radius*radius*Math.PI;
}
public Double getPerimeter1() //获得圆的周长
{
return 2*Math.PI*radius;
}
public void disp1() //将圆的半径,周长,面积 输出到屏幕
{
System.out.printf("圆的半径为:%.2f,周长:%.2f,面积:%.2f", radius,getPerimeter1(),getArea1());
}
public class Cylinder extends Circle1 {
private double hight;
public Cylinder (double r, double h ){
super(r);
this.hight = h;
}
public double getVolume(){
return Math.PI * this.getRadius() * this.getRadius() * hight;
}
public void showVolume( ){
System.out.println("圆柱体的体积:" + this.getVolume());
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("输入半径:");
double r = s.nextDouble();
Circle1 c = new Circle1(r);
c.disp1();
}
}