Monday, January 20, 2014

Java Program to Find Area of Shapes Using Method Overloading

with 0 Comment
import java.io.*
import java.lang.*;
import java.text.*;
class shape
{
int area,length,breadth1;
double breadth,height;
int area(int a)
{
return(a*a);
}
double area(double b,double h)
{
return(0.5*b*h);
}
double area(int l,int b1)
{
return(l*b1);
}
}
class volume1
{
public static void main(String args[])throws IOException,ParseException
{
int a,b1,l;
double b,h;
DecimalFormat df=new DecimalFormat('###.##");
DataInputStream d=new DataInputStream(System.in);
shape s=new shape();
System.out.println("Volume of Shape Using Method Overloading");
System.out.println("**************************");
System.out.println("Area of Square");
System.out.println("*********");
System.out.println("Enter the area of value");
a=Integer.parseInt(d.readLine());
System.out.println("Area of Triangle");
System.out.println("*********");
System.out.println("Enter the breadh & height"):
b=Double.parseDouble(d.readLine());
h=Double.parseDouble(d.readLine());
System.out.println("Area of Rectangle");
System.out.println("***********");
System.out.println("Enter the Length and breadh");
l=Integer.parseInt(d.readLine());
b1=Integer.parseInt(d.readLine());
int square=s.area(a);
double tri=s.area(b,h);
tri=df.parse(df.format(tri)).doubleValue();
double rect=s.area(l,b1);
rect=df.parse(df.format(rect)).doubleValue();
System.out.println("Area of Square="+square);
System.out.println("Area of triangle="+tri);
System.out.println("Area of rectangle="+rect);
}
}

------------
OUTPUT:
********
Area of Shape Using Method Overloading
**********************************
Area of Square
************
Enter the area of value:
3
Area of Triangle
*************
Enter the breadh & height:
4.5
2.6
Area of Rectangle
***************
Enter the length and breadh:
6
3
Result:
*****
Area of Square=9
Area of Triangle=5.85
Area of Rectangle=18.0

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive