Enter the radius of the circle and the height h of the cylinder to find the circumference and area of the circle and use the radius of the circle to find the volume of the cylinder

package Interface;
import javax.swing.JOptionPane;
public class Circle implements Area,Perimeter,Volume
{
    double r;
    double h;
    Circle()

{
        this(3,10);
    }
    Circle(double r,double h)

{
        this.h=h;
        this.r=r;
        
    }
    public static void main(String[] args)
    {
        String str1=JOptionPane.showInputDialog("Please enter the radius of the circle:");
        double r=Double.parseDouble(str1 );
        String str2=JOptionPane.showInputDialog("Please enter the height of the cylinder:");
        double h=Double.parseDouble(str2);
        Area Circle=new Circle(r,h);
        JOptionPane.showMessageDialog(null,"Circle Radius: "+r);
        JOptionPane.showMessageDialog(null,"Area of ​​the circle:"+Circle.area());
        Volume Circle1=new Ciecle(r,h);
        JOptionPane.showMessageDialog(null,"Volume of the cylinder: "+Circle1.volume());
        Perimeter Circle2=new Ciecle(r,h);
        JOptionPane.showMessageDialog(null,"圆的周长:"+Circle2.perimeter());
        
    }

    public double area(){
        return Math.PI*r*r;
    }
    public double perimeter(){
        return 2*Math.PI*r;
    }
    public double volume() {
    return this.area()*this.h;
    }
}
面积接口

package Interface;

public interface Area {
    public abstract double area();
}
周长接口

package Interface;

public interface Perimeter {
    public abstract double perimeter();
}
The volume interface of the cylinder

package Interface;

public interface Volume
{
    public abstract double volume();
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324738792&siteId=291194637
Recommended