Instructions

Create a class named Circle with a field for the radius. Be sure to include the following:

  • a default constructor that sets the radius to 1
  • a method to set the value of the radius
  • a method to return the value of the radius
  • a method to compute and return the circle's diameter
  • a method to compute and return the circle's area

Recall that the diameter of a circle is twice its radius and that the area of a circle is 3.14 times the square of its radius.

After creating this class, write a second class, TestCircle, that has a main() method in it. Have this program create a Circle object with radius 10. It should also create a second Circle object that uses the radius set by the default constructor. Once the objects have been created, write code to display the diameter and area of both circles in an attractive fashion.

Although the output from your program is not required to look this way, it might look something like:

The Circle with radius 10.0 has diameter 20.0 and area 314.0.
The Circle with radius 1.0 has diameter 2.0 and area 3.14.

When you are finished, submit both the Circle.java and CircleTest.java files for grading.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.