A Write a circle class circle, which has:
① a member variable
radius//the radius of the circle; private, floating point type
② Two construction methods
Circle ()//set RADIUS to 0
Circle (Doubler)////Create Circle object with radius initialized to R
③ Three Member methods
Double Getarea ()//Get the area of a circle
Double Getperimeter ()//Get the perimeter of a circle
void Show ()//Output the radius, perimeter, area of the circle to the screen
Write a cylindrical class cylinder, which inherits from the Circle class above. also has:
① a member variable
Double hight//height of cylinder, private, floating point type
② Construction Method
Cylinder (Double R, Double h)//When the Circle object is created, the radius is initialized to R
③ Member method
Double Getvolume ()//Get the volume of a cylinder
void Showvolume ()//output The volume of a cylinder to the screen
Write the application, create two classes of objects, set the radius of the circle, the height of the cylinder, calculate and show the circle radius, circle area, circumference length, cylinder volume.
public class Circle {
private double Radius;
Public Circle () {
radius=0;
}
Public Circle (double radius) {
super ();
radius = radius;
}
Public double Getarea () {return
math.pi*radius*radius/2;
}
Public double Getperimeter () {return
2*math.pi*radius;
}
public void Show () {
System.out.println ("radius of Circle:" +radius);
System.out.println ("Area of the Circle:" +getarea ());
System.out.println ("Circumference of Circle:" +getperimeter ());
}
public class Cylinder extends Circle {
private double hight;
Public Cylinder (Double r,double h) {
super (R);
this.hight=h;
}
Public double Getvolume () {return
getarea () *hight;
}
public void Show () {
System.out.println ("Cylinder Volume:" +getvolume ());
}
public static void Main (string[] args) {
double r=1;
Double h=2;
Cylinder c=new Cylinder (r,h);
Circle c1=new Circle (r);
C1.show ();
C.show ();
}