Question
In this exercise, youll create an application that computes the diameter, circumference, and area of a circle. A sample run of the application should look
In this exercise, youll create an application that computes the diameter, circumference, and area of a circle.
A sample run of the application should look like this
Create a new project and a Circle class
1. Start NetBeans and use it to create a new project named ch04_ex3_Circle.
Make sure you create a Main class and put it in a package. You can use murach.circle as the name of the package.
2. Create a new class named Circle and store it in the murach.circle package.
3. In the Circle class, add an instance variable for the radius of the circle.
If possible, use the IDE to generate get and set methods for this variable.
4. Add a constructor to the Circle class that doesnt take any arguments.
This constructor should set the instance variable for the radius to 0.
5. Add a method named getDiameter that returns the diameter of the circle.
To do that, this method can multiply the radius by 2.
Use the Circle class 6. Add code to the main method that gets the radius of the circle from the user.
7. Add code that creates a Circle object. Then, add code that uses the setRadius to set the radius in the Circle object.
8. Add code that uses the getDiameter method to get the diameter from the Circle object. Then, add code that displays the diameter.
9. Run the application to make sure it works correctly.
Add the circumference and area to the application
10. Add a method named getCircumference that calculates and returns the circumference of the circle.
To do that, you can multiply Pi by 2. You can use 3.14159 as the value of Pi.
11. Add a method named getArea that calculates and returns the area of the circle.
To do that, the code for this method can multiply Pi by the radius squared, which is the radius multiplied by the radius.
12. Add code to the main method that uses the getCircumference and getArea methods to display the circumference and area of the Circle object.
13. Run the application and make sure it works correctly.
Add a second constructor to the Circle class and use it
14. Add a second constructor to the Circle class that takes an argument for the radius.
This constructor should sets the instance variable for the radius to the value of the argument.
15. Modify the code in the main method so it uses the second constructor to create the Circle object.
16. Comment out the statement that uses the setRadius method since that method is no longer necessary.
Welcome to the Circle Calculator Enter radius: 10 Diameter: Circunference: 62.8318 Area: 20.0 314.159 Continue? (y): nStep 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