Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Eva Goins
- * Chapter 6
- * Description: The class Circle has the fields radius (double)
- * and PI (final double), the constructors Circle that allows
- * immediate input of the radius, and the no args constructor.
- * The class also uses methods setRadius to set the radius
- * should it be user-input, getRadius to obtain the radius
- * currently set, getArea to calculate the area, getDiameter
- * to calculate the diameter, and getCircumference to calculate
- * the circumference. All non-constructor methods return a
- * double value.
- */
- public class Circle
- {
- double radius;
- final double PI = 3.14159;
- public Circle(double rad)
- {
- radius = rad;
- }
- public Circle()
- {
- radius = 0.0;
- }
- public void setRadius(double rad)
- {
- radius = rad;
- }
- public double getRadius()
- {
- return radius;
- }
- public double getArea()
- {
- return PI * radius * radius;
- }
- public double getDiameter()
- {
- return radius * 2;
- }
- public double getCircumference()
- {
- return 2 * PI * radius;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement