
Requirement
In this Assignment, you should write a class that, given a circle’s radius, has methods that return the circle’s area, diameter, and circumference.
In case you have forgotten, the equations for a circle’s area, diameter, and circumference is given below.
1 |
area = πrr |
Based on Chapter 3, Programming Challenge # 8 Circle class in your textbook. Your output is given below.
1 |
Enter the radius of a circle: 5.3 |
Write a separate class called CircleDemo with a main method that asks the user for the circle’s radius, creates a Circle object, and then reports the circle’s area, diameter, and circumference using the circle’s getter methods.
Analysis
本题需要的数学背景见Pi,需要实现一个Circle类,以及对应的方法,如setRadius(),getRadius(),getArea(),getDiameter(),getCircumference()。
本题较为简单,注意数据类型,精度以及输入输出格式即可。
Tips
下面是ClicleDemo类的实现
1 |
class { |




近期评论