Program:
package ar.peri;
import java.io.IOException;
import java.io.InputStreamReader;
public class ArPeri {
public
static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter your choice");
System.out.println("1. To find Area & Perimeter of a
Rectangle");
System.out.println("2. To Find Area & Perimeter of a
Square");
System.out.println("3. To Find Area & Perimeter of a
Circle");
System.out.println("4. To Find Area & Perimeter of a
Equilateral Triangle");
System.out.println("5. To Find Area & Perimeter of a Parallelogram");
System.out.println("6. To Find Area & Perimeter of a Rhombus");
int
choice=Integer.parseInt(br.readLine());
switch(choice){
case 1:
//code
to be executed for rectangle;
System.out.println("You have selected to Find Area & Perimeter
of a Rectangle");
System.out.print("Enter the value os side a ");
int a
=Integer.parseInt(br.readLine());
System.out.print("Enter the value os side b ");
int b
=Integer.parseInt(br.readLine());
int
p1=2*(a+b);
int
area1=a*b;
System.out.println(" Area = "+ area1 + " & Perimeter
of a Rectangle="+p1);
break;
case 2:
//code to
be executed for square;
System.out.println("You have selected to Find Area & Perimeter
of a Square");
System.out.print("Enter the value of side c ");
int c
=Integer.parseInt(br.readLine());
int
p2=4*(c);
int
area2=c * c;
System.out.println(" Area = "+ area2 + " & Perimeter
of a Square="+p2);
break;
case 3:
//code to
be executed for circle;
System.out.println("You have selected to Find Area & Perimeter
of a Circle");
System.out.print("Enter the radius ");
int r
=Integer. parseInt(br.readLine());
float
p3=(float) (2.0*3.14* r) ;
float
area3=(float) (3.14 * r* r);
System.out.println(" Area = "+ area3 + " & Perimeter
of a Circle="+p3);
break;
case
4:
//code to
be executed for Equilateral Triangle ;
System.out.println("You have selected to Find Area & Perimeter of a Equilateral
Triangle");
System.out.print("Enter the side ");
int s
=Integer. parseInt(br.readLine());
int
p4= 3* s ;
float
area4=(float)((1.0/4.0)*(Math.sqrt(3.0))* s*s );
System.out.println(" Area = "+ area4 + " & Perimeter
of a Equilateral Triangle="+p4);
break;
case
5:
//code to
be executed for Parallelogram ;
System.out.println("You have selected to Find Area & Perimeter
of a Parallelogram");
System.out.print("Enter
the side a");
int s1
=Integer. parseInt(br.readLine());
System.out.print("Enter the side
b");
int s2
=Integer. parseInt(br.readLine());
int
p5=2*(s1 + s2);
int
area5= s1 * s2;
System.out.println(" Area = "+ area5 + " & Perimeter
of a Parallelogram="+p5);
break;
case
6:
//code to
be executed for Rhombus;
System.out.println("You have selected to Find Area & Perimeter
of a Rhombus");
System.out.print("Enter the side
a");
int a6 =Integer. parseInt(br.readLine());
System.out.print("Enter the side
height");
int h
=Integer. parseInt(br.readLine());
int
area6=a6 * h;
int p6=
4 * a6;
System.out.println(" Area = "+ area6 + " & Perimeter
of a Rhombus="+p6);
break; //optional
default:
System.out.println("Please select your choice between 1-6");
}
}
}
OUTPUT 1:
OUTPUT 2:
No comments:
Post a Comment