Question: Create a class named Circle with one field (instance variable) called radius and with the methods getRadius and setRadius . Define a constructor for the

Create a class named Circle with one field (instance variable) called radius and with the methods getRadius and setRadius. Define a constructor for the class which sets the value of the radius to 1. Define the following methods in this class:

computeDiameter() which computes the diameter of the circle (diameter = 2 * radius) and returns it to the calling function.

computeArea() which computes the area of the circle (area = 3.14 * r *r) and returns it to the calling function.

Save the class as Circle.java

Create an application class called TestCircle whose main method declares three circle objects. Assign a small value to the radius of the first circle object and assign a fairly large value to the radius of the second circle object and leave the third circle object with the default value. Call computeDiameter and computeArea for each circle object and display the results returned by these functions in the main method.

Save the class as TestCircle.java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!