Wednesday, January 16, 2008

[menudriven]-Area Of all the Shapes

import java.io.*;
class Ar
{
double a;
public void area(int x)
{
a = (3.14)*x*x;
System.out.println(" Area = " + a);
}
public void area()throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int s;
System.out.println(" Enter side ");
s = Integer.parseInt(in.readLine());
a = s*s;
System.out.println(" area " + a);
}
public void area(float l,float b)
{
a = l*b;
System.out.println(" area = " + a);
}
public double area (int h,int p)
{
a = (0.5)*h*p;
return a;
}
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
System.out.println(" 1 : circle ");
System.out.println(" 2 : square ");
System.out.println(" 3 : rectangle ");
System.out.println(" 4 : triangle ");
System.out.println(" Enter your choice ");
int c;
Ar a1 = new Ar();
c = Integer.parseInt(in.readLine());
if(c==1)
{
int r;
System.out.println(" enter radius ");
r = Integer.parseInt(in.readLine());
a1.area(r);
}
else if(c == 2)
{
a1.area();
}
else if(c == 3)
{
float p,q;
System.out.println("enter length and breadth ");
p=Float.parseFloat(in.readLine());
q=Float.parseFloat(in.readLine());
a1.area(p,q);
}
else if(c == 4)
{
int y,z;
double d;
System.out.println(" enter base and hieght ");
y = Integer.parseInt(in.readLine());
z = Integer.parseInt(in.readLine());
d = a1.area(y,z);
System.out.println(d);
}
else
System.out.println(" Invalid ");
}
}


Its made using fuctions

No comments: