Write a Circle class that has the following fields: Radius: a double PI: a final
Question:
Write a Circle class that has the following fields:
• Radius: a double
• PI: a final double initialized with the value 3.14159
The class should have the following methods:
• Constructor. Accepts the radius of the circle as an argument.
• Constructor. A no-arg constructor that sets the radius field to 0.0.
• SetRadius. A mutator method for the radius field.
• GetRadius. An accessor method for the radius field.
• GetArea. Returns the area of the circle, which is calculated as Area = PI * radius * radius
• GetDiameter. Returns the diameter of the circle, which is Calculated as Diameter = radius * 2
• GetCircumference. Returns the circumference of the circle, which is calculated as Circumference = 2 * PI * radius
Write a program that demonstrates the Circle class by asking the user for the circle’s radius, creating a Circle object, and then reporting the circle’s area, diameter, and circumference.
Step by Step Answer:
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis