输入圆的半径 圆柱体的高h 求出圆的周长与面积 并利用该圆的半径求出圆柱体的体积
2018-04-23 22:00 lang'sblog 阅读(699) 评论(0) 编辑 收藏 举报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("请输入圆的半径:");
double r=Double.parseDouble(str1);
String str2=JOptionPane.showInputDialog("请输入圆柱体的高:");
double h=Double.parseDouble(str2);
Area Circle=new Circle(r,h);
JOptionPane.showMessageDialog(null,"圆的半径:"+r);
JOptionPane.showMessageDialog(null,"圆的面积:"+Circle.area());
Volume Circle1=new Ciecle(r,h);
JOptionPane.showMessageDialog(null,"圆柱体的体积:"+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();
}
圆柱体的体积接口
package Interface;
public interface Volume
{
public abstract double volume();
}