write a program with the name area using function overloading that computes the area of parallelogram, rhombus and trapezium in java
Answers
Answer:
Explanation:
class OverloadDemo
{
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");
}
}
class Overload
{
public static void main(String args[])
{
OverloadDemo ob = new OverloadDemo();
ob.area(5);
ob.area(11,12);
ob.area(2.5);
}
}
Question:-
➡Write a class with the name area using function overloading that computes the area of parallelogram, rhombus and trapezium in java.
Program:-
import java.util.*;
class Area
{
void area(int base, int height)
{
double a=0.5*base*height;
System.out.println("Area of the Parallelogram is: "+a);
}
void area(double d1, double d2)
{
double a=0.5*d1*d2;
System.out.println("Area of the Rhombus is: "+a);
}
void area(double h, double a, double b)
{
double A=0.5*h*(a+b);
System.out.println("Area of the trapezium is: "+A);
}
public static void main(String args[])
{
Area obj=new Area();
obj.area(2,3);
obj.area(20.0,50.0);
obj.area(10.0,20.0,20.0);
}
}