package code
pkj of-circle
package p;
public class circle
{
double a;
double pi=3.14;
public double circlearea(int h)
{
a=pi*h*h;
return a;
}
}
pjk of-rect
package p;
public class rect
{
double a;
public double rectarea(double l,double b)
{
a=l*b;
return a;
}
}
pkj of –triangle
package p;
public class triangle
{
double a;
double t=0.5;
public double triarea(double b,double h)
{a=t*b*h;
return a;
}
}
import p.*;
import java.io.*;
class areademo
{
public static void main(String args[])
{int d,h,b,a,s;
String choice;
int ch;
circle c=new circle();
rect r=new rect();
triangle t=new triangle();
try
{
DataInputStream in=new DataInputStream(System.in);
do
{ System.out.println("Enter your choice");
System.out.println("1.Area of Circle.");
System.out.println("2.Area of Triangle.");
System.out.println("3.Area of Rectangle.");
ch=Integer.parseInt(in.readLine());
switch(ch)
{
case 1:
System.out.println("Enter radius of circle");
d=Integer.parseInt(in.readLine());
System.out.println("Area of circle="+c.circlearea(d));
break;
case 2:
System.out.println("Enter base & height of triangle");
b=Integer.parseInt(in.readLine());
h=Integer.parseInt(in.readLine());
System.out.println("Area of Triangle="+t.triarea(b,h));
break;
case 3:
System.out.println("enter the length & breadth");
a=Integer.parseInt(in.readLine());
s=Integer.parseInt(in.readLine());
System.out.println("area="+r.rectarea(a,s));
break;
default:
System.out.println("invalid entry");
}
System.out.println("do you want to continue enter y or n");
choice=in.readLine();
}
while(choice.equals("y"));
}
catch(IOException ex)
{
System.out.println("Error");}}}
OUTPUT:
0 comments:
Post a Comment