Area of Shapes

Using function overloading calculate area of a triangle, rhombus and circle.

Area of Triangle: s*(s-a)*(s-b)*(s-c) where s = (a+b+c)/2

Area of Rhombus: (1/2)*product of diagonals

Area of Circle: π*r2

Take all required inputs from main functions and invoke the function which calculates area using class object.

Java
import java.util.*;
public class Area
{
    double area=0.0;
    public void getArea(double a,double b,double c)
    {
        double s=(a+b+c)/2;
        area=(s*(s-a)*(s-b)*(s-c));
        System.out.println("Area of Triangle: "+area);
    }
    public void getArea(double d1,double d2)
    {
        area=0.5*d1*d2;
        System.out.println("Area of Rhombus: "+area);
    }
    public void getArea(double r)
    {
        area=(22/7)*r*r;
        System.out.println("Area of Circle: "+area);
    }
    public static void main(String args[])
    {
        double x=0.0,y=0.0,z=0.0,d1=0.0,d2=0.0,r=0.0;
        Area ob=new Area();
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter three sides of triangle:-");
        System.out.print("A: ");
        x=sc.nextDouble();
        System.out.print("B: ");
        y=sc.nextDouble();
        System.out.print("C: ");
        z=sc.nextDouble();
        System.out.println("Enter two diagonals of rhombus:-");
        System.out.print("D1: ");
        d1=sc.nextDouble();
        System.out.print("D2: ");
        d2=sc.nextDouble();
        System.out.print("Enter radius of circle: ");
        r=sc.nextDouble();
        ob.getArea(x,y,z);
        ob.getArea(d1,d2);
        ob.getArea(r);
    }
}
Java