求解Java
来源:百度知道 编辑:UC知道 时间:2024/06/01 18:27:41
To produce a program that calculates and outputs the circumference and area of a circle
given its radius.
You are asked to model the system by two classes. An application class Driver containing
the main method, and a class Circle storing the radius of the circle. Such class will have
the responsibility to compute the two required numerical outputs: the length of the
circumference and the area of the circle (as results of methods with the same name).解这道题 小弟在此谢过 很重要的哦
given its radius.
You are asked to model the system by two classes. An application class Driver containing
the main method, and a class Circle storing the radius of the circle. Such class will have
the responsibility to compute the two required numerical outputs: the length of the
circumference and the area of the circle (as results of methods with the same name).解这道题 小弟在此谢过 很重要的哦
public class Circle
{
public final static double PI=3.14;
private double radius;
private double outputs;
public Circle(double radius)
{
this.radius=radius;
}
public double getCircumference()
{
outputs=2*PI*radius;
return outputs;
}
public double getArea()
{
this.outputs=PI*radius*radius;
return outputs;
}
}
public class Driver
{
public static void main(String args[])
{
Circle c=new Circle(3.0);
System.out.println("The circle's circumference is:"+c.getCircumference());
System.out.println("The circle's area is :"c.getArea());
}
}
太简单了自己动手吧,无非就是写两个类一个圆一个交通工类交通工具类继承圆类,自己动手