要编写Java应用程序,该程序包含两个类,一个圆形类、一个圆柱体类。圆形类包含类变量半径、面积,还具有从键盘输入得到半径以及计算面积的方法。圆柱体类从圆形类派生而来,要求能从键盘输入得到圆柱体的高,以及计算圆柱体体积的方法。
1、用编辑工具JCreator编写Java代码,在JDK环境下编译运行,实现应用程序指定的功能。
2、程序代码格式整齐规范、便于阅读。
3、程序注释完整规范、简明易懂。
能写一下程序吗?
追答class Circle //*********圆
{
double r;
public Circle()
{}
public Circle(double r)
{
this.r = r;
}
public double area()
{
return 3.14 * r * r;
}
public double perimeter() //圆的周长
{
return 3.14 * 2 * r;
}
}
class Cylinder
extends Circle //圆柱
{
double height;
public Cylinder()
{}
public Cylinder(double r, double height)
{
super(r);
this.height = height;
}
public double area()
{
return super.perimeter() * height + 2 * super.area();
}
public double volume()
{
return super.area() * height;
}
}