010-001-011
Area Calculation with Overloading
Medium
Problem Description
Area Calculation with Overloading
In this problem, you will create a program that defines three overloaded calcArea methods with different parameter types and counts to calculate the areas of a square, rectangle, and circle using values read from standard input, and displays the results.
Learning Objective: Practice method overloading by varying both the number and types of parameters
Overview
Define three methods all named calcArea to calculate the area of a square, rectangle, and circle using Scanner input.
Specifications
calcArea(int side): returns the area of a square (side * side)calcArea(int width, int height): returns the area of a rectangle (width * height)calcArea(double radius): returns the area of a circle (Math.PI * radius * radius) rounded to 2 decimal places- Call each method from main and output the results with labels
Input Format
side
width
height
radius
Output Format
Square: <square area>
Rectangle: <rectangle area>
Circle: <circle area (2 decimal places)>
Sample Input/Output
Input:
5
4
6
3.0
Output:
Square: 25
Rectangle: 24
Circle: 28.27
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up