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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started