Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Circle class that has the following fields: radius: a double PI: a final

ID: 3537905 • Letter: W

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

getDiamete: 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%u2019s radius, creating a circle object, and then reporting the circle%u2019s area, diameter and circumference.

Explanation / Answer

Create a class named Circle with data members radius of type double and PI of type final double initialized to 3.14159 Contains a constructor that takes the radius of a circle as an argument and initializes the radius data member to that value Contains a no argument constructor that sets the radius data member to 0.0 Contains a method named setRadius that takes the radius of a circle as an argument and sets the circle's data member radius to that value Contains a method named getRadius that has no arguments and simply returns the radius as a double Contains a method named getArea that has no arguments and returns the area of the circle as a double by multiply PI by the radius squared Contains a method named getDiameter that has no arguments and returns the diameter of the circle as double by multiplying the radius by 2 Contains a method named getCircumference that has no arguments and returns the circumference of the circle as a double by multiplying PI by twice the radius In a driver class inside the main function, ask the user for the circle's radius, create a Circle with that radius, and then print the circle's area, diameter, and circumference.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote