Professional Documents
Culture Documents
20bca1177 (Roshan) Ip 3
20bca1177 (Roshan) Ip 3
2. Task to be done:
Java Program to Find Area of Square, Rectangle, and Circle using Method Overloading
3. Algorithm/Flowchart :
I. Start
II. Declare three methods of the same name but with a different number of
arguments or with different data types.
III. Call these methods using objects.
IV. Call the corresponding methods as per the number of arguments or their
data types.
V. Display the result.
VI. Stop.
Flowchart
4. Code for experiment/practical:
//Java Program to Find the area of Square, Rectangle and Circle using
Method Overloading
public class Main
{
//Driver Code
public static void main(String[] args)
{
CalculateArea ob = new CalculateArea();
ob.area(4);
ob.area(10,12);
ob.area(5.5);
}
}
class CalculateArea
{
void area(float x)
{
System.out.println("The area of the square is "+Math.pow(x, 2)+" sq
units");
}
void area(float x, float y)
{
System.out.println("The area of the rectangle is "+x*y+" sq units");
}
void area(double x)
{
double z = 3.14 * x * x;
System.out.println("The area of the circle is "+z+" sq units");
}
}
5. Result/Output/Writing Summary:
1.Learning outcomes (What I have learnt):
1. Finding the area of squares, rectangles, and circles using method
overloading.
2. The area of the rectangle is the product of its length and
width/breadth.
3. The area of the circle is the product of the square of the radius of
the circle and the value of PI.
4. The area of the square is the square of its sides.
5. If a class has multiple methods having the same name but
different in parameters, it is known as Method Overloading.
Evaluation Grid: