Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please answer this java code 3. Write a Java program to do the following: Create a class named Circle with the following contents: Private fields

please answer this java code image text in transcribed
image text in transcribed
3. 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. Your output must look exactly like the pictures on the next page. Sample runs: Windows lastemade Circle Characteristics: Radius: Diameter: Area! Circunference 1.80 2.800 3.142 6.283 Enter a radius value: 1.5 Circle Characteristics: Radius: 1.500 Dianeter: Area: 7.869 Circunference: 9.425 Windowsystement Circle Characteristics: Radius: Diameter: Area: Circunference: 1.ee 2.00 3.142 6.283 Enter a radius value: 6.59 Circle Characteristics: Radius 6.590 Dianter: 13.188 Rrea: 136.433 Circunferencet 11.486 You will submit this assignment (including both the circle.java and the Testcircle.java files) using the 'Assignment #3" link in Blackboard

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions