Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program to do the following: Create a class named Circle with the following contents: Private fields named radius, diameter, and area. A

Write a Java program to do the following: Create a class named Circle with the following contents: Private fields named radius, diameter, and area.

A private computeDiameter() method to calculate the diameter of circle. The diameter of a circle is twice the radius.

A private computeArea() method to calculate the area of a circle. The area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation. A public getCircumference() method to calculate and return the circumference of a circle. The circumference of a circle can be calculated as pi multiplied by twice the radius. Use the Math class PI constant for this calculation.

A public setRadius() method that will set the radius based on a value that is passed to the method. This method also needs to call the computeDiameter() and computeArea() methods. Public methods named getRadius(), getDiameter() and getArea(). These methods will return the values for radius, diameter, and area.

A constructor that sets the radius to 1 and calculates the diameter and area. Create a class named TestCircle using these instructions: Write a method named printCharacteristics that takes a single argument of type Circle. This method will display the radius, diameter, area and circumference of a Circle object. These values need to be displayed to 3 decimal places (see example of output below).

Write a method named inputRadius that takes a single argument of type Circle. This method will prompt the user for a radius value, and will set the radius of the Circle object to that value. Declare/instantiate 1 Circle object using the constructor method.

Display the radius, diameter, area and circumference of this object.

Prompt the user for a radius value, and set the radius of the object to that value.

Display the new radius, diameter, area and circumference of the object.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

You have

Answered: 1 week ago