In this exercise, you are going to build on your Circleclass from the previous exercise. You are going to add 2 method, areaDifference and perimeterDifference. Both methods take a doubleradius of a second circle and return the difference from the current circle. For example, if you create a Circle object with a radius of 4 and call areaDifference(3), you will return the diffence between the area of a circle with radius 4 and the area of a circle with a radius of 3. perimeterDifferencewould be the same. Make sure you create at least one Circle and test and print the results of your methods. given: public class Circle { private double radius; public Circle(double theRadius){ radius = theRadius; } // Add a method called area that returns the area of a circle // using Math.PI public double area() { return Math.PI*radius*radius; } // Add a method called perimeter that returns the perimeter of a // circle using Math.PI public double perimeter() { return Math.PI*2*radius; } }
In this exercise, you are going to build on your Circleclass from the previous exercise.
You are going to add 2 method, areaDifference and perimeterDifference. Both methods take a doubleradius of a second circle and return the difference from the current circle.
For example, if you create a Circle object with a radius of 4 and call areaDifference(3), you will return the diffence between the area of a circle with radius 4 and the area of a circle with a radius of 3. perimeterDifferencewould be the same.
Make sure you create at least one Circle and test and print the results of your methods.
given: public class Circle
{
private double radius;
public Circle(double theRadius){
radius = theRadius;
}
// Add a method called area that returns the area of a circle
// using Math.PI
public double area()
{
return Math.PI*radius*radius;
}
// Add a method called perimeter that returns the perimeter of a
// circle using Math.PI
public double perimeter()
{
return Math.PI*2*radius;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images