Computer Science, asked by richamishra207, 6 months ago

write a class with the name area using function overloading that computes the area of parallelogram, rhombus and trapezium in java​

Answers

Answered by keyboardavro
3

Answer:

mate if this answer is correct please mark me brainliest

Explanation:

class JavaExample

{

   void calculateArea(float x)

   {

       System.out.println("Area of the square: "+x*x+" sq units");

   }

   void calculateArea(float x, float y)

   {

       System.out.println("Area of the rectangle: "+x*y+" sq units");

   }

   void calculateArea(double r)

   {

       double area = 3.14*r*r;

       System.out.println("Area of the circle: "+area+" sq units");

   }

   public static void main(String args[]){

       JavaExample obj = new JavaExample();

       

       /* This statement will call the first area() method

        * because we are passing only one argument with

        * the "f" suffix. f is used to denote the float numbers

        *  

        */

 obj.calculateArea(6.1f);

   

 /* This will call the second method because we are passing  

  * two arguments and only second method has two arguments

  */

 obj.calculateArea(10,22);

   

 /* This will call the second method because we have not suffixed

  * the value with "f" when we do not suffix a float value with f  

  * then it is considered as type double.

  */

 obj.calculateArea(6.1);

   }

}

Output:

Area of the square: 37.21 sq units

Area of the rectangle: 220.0 sq units

Area of the circle: 116.8394 sq units

Answered by anindyaadhikari13
3

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);

}

}

Similar questions