import java.io.*;
class Menu
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a;
public void takeChoice()throws Exception
{
System.out.print("\nEnter 1 for area of circle, 2 for square and 3 for rectangle:");
a=Integer.parseInt(br.readLine());
if(a==1)
circle();
else if(a==2)
square();
else if(a==3)
rectangle();
}
public void circle() throws Exception
{
double area;
int r;
System.out.print("\nEnter the radius:");
r=Integer.parseInt(br.readLine());
area=22.0/7*r*r;
System.out.print("\nArea of the circle:"+area);
}
public void square() throws Exception
{
int area;
int s;
System.out.print("\nEnter the side:");
s=Integer.parseInt(br.readLine());
area=s*s;
System.out.print("\nArea of the square:"+area);
}
public void rectangle() throws Exception
{
int area;
int a1,a2;
System.out.print("\nEnter the width:");
a1=Integer.parseInt(br.readLine());
System.out.print("\nEnter the breadth:");
a2=Integer.parseInt(br.readLine());
area=a1*a2;
System.out.print("\nArea of the Rectangle:"+area);
}
public static void main(String args[])throws Exception
{
Menu ob=new Menu();
ob.takeChoice();
}
}
Related Post: BlueJ Menu Based Programs
No comments:
Post a Comment