上传者: yx_222
|
上传时间: 2021-10-31 15:23:17
|
文件大小: 3KB
|
文件类型: -
Create a class called Circle.java with fields named radius, area, and diameter. Include methods named setRadius(), getRadius, and computeDiameter(), which calculates the circle's diameter, and computeArea(), which computes the circle's area.
Hint: diameter of a circle is twice its radius.
Hint: area of a circle is 3.14 multiplied by the square of the radius.
Create a class called TestCircle. java whose main method declares 2 Circle objects. Using setRadius() method, assign one Circle a small radius value and assign another a larger radius value. Call computeDiameter() and computeArea for each circle and display the results.
Output result of using command input "5 8":
The area of a is 78.5
The diameter of a is 10.0
The area of b is 200.96
The diameter of b is 16.0