Design a class to overload a function areal ) as follows ) double area(double a double b, double c) with three double arguments, find the area of scalene triangle using the formula Area= sqrt s(s-a) (s-b(s-c) , where s = (a + b + c)/2 (1) double area(int a, int b, int height) with three integer arguments, find the area of a trapezium using the formula 1 * height (a+b) (1) double area double diagonall, double diagonal 2) with two double arguments, returns the area of a rhombus using the formula Area = (diagonal diagonal 2) 2 Area = 2
Answers
Answered by
1
Answer:
public class Main
{
double at=0.0,atr=0.0,ar=0.0;
double area(double a,double b,double c)
{
double s=0;
s=(a+b+c)/2.0;
at=Math.sqrt(s*(s-a)*(s-b)*(s-c));
return at;
}
double area(int a,int b,int height)
{
atr=1.0/2.0*(a+b)*height;
return atr;
}
double area(int d1,int d2)
{
ar=1.0/2.0*d1*d2;
return ar;
}
public static void main(String args[ ])
{
Main sh=new Main();
System.out.println("The area of triangle="+sh.area(3.0,4.0,5.0));
System.out.println("The area of trapezium="+ sh.area(7,9,10));
System.out.println("The area of rhombus="+sh.area(10,12));
}
}
Refer to the attachment for output:-
- You may check the answer practically though I have checked.
Attachments:
Similar questions