Java Program to find geometrical figure using method overloading.

Below code is used  to find geometrical figure using Method Overloading:

import java.util.Scanner;

class Geofig
{
        double area(double r)
        {
        return(3.14*r*r);
        }
        float area(float s)
        {
         return(s*s);
        }
        float area(float l,float b)
        {
        return(l*b);
        }
        double area(double b1,double h)
        {
        return(0.5*b1*h);
        }
        public static void main(String[] args)
        {             
                Scanner sc=new Scanner(System.in);
                Geofig g=new Geofig();      
                System.out.println("Enter the value of radius of circle");
                System.out.println();
                double r=sc.nextDouble();
                System.out.println("Area of circle =" +g.area(r));

                System.out.println("Enter the value for side of square");
                System.out.println();
                float s=sc.nextFloat();
                System.out.println("Area of square =" +g.area(s));

                System.out.println("Enter the value of lenght and breath of rectangle");
                System.out.println();
                float l=sc.nextFloat();
                float b=sc.nextFloat();
                System.out.println("Area of rectangle =" +g.area(l,b));
                        
                System.out.println("Enter the value of breath and height of rectangle");
                System.out.println();
                double b1=sc.nextFloat();
                double h=sc.nextFloat();
                System.out.println("Area of triangle =" +g.area(b1,h));
        }
}
Thank You.

© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT