Question

Java: Write a class that had two overloaded static methods for calculating the areas of the...

Java:

Write a class that had two overloaded static methods for calculating the areas of the following geometric shapes:

circles

rectangles

Here are the formulas for calculating the area of the shapes:

Area of a circle: Area = πr^2

where π is Math.PI and r is the circle's radius

Area of a rectangle: Area = Width * Length

Because the two methods are to be overloaded, they should each have the same name, but different parameter lists. Demonstrate the class in a complete program.

Example run:

run:

The area of a circle with a radius of 20.0 is 1256.64

The area of a rectangle with the length of 10 and width of 20 is 200.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class Areas {

    public static double area(double radius) {
        return Math.PI * radius * radius;
    }

    public static double area(double width, double length) {
        return width * length;
    }

    public static void main(String[] args) {
        System.out.println("The area of a circle with a radius of 20.0 is " + area(20));
        System.out.println("The area of a rectangle with the length of 10 and width of 20 is " + area(10, 20));
    }
}

Add a comment
Know the answer?
Add Answer to:
Java: Write a class that had two overloaded static methods for calculating the areas of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT