-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.java
67 lines (57 loc) · 2 KB
/
Shape.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.*;
class Shape{
double redious;
double height;
double width;
Shape(double redious){
this.redious = redious;
}
Shape(double height, double width){
this.height = height;
this.width = width;
}
double getPerimeter(double radious){
double perimeter = Math.PI * redious * 2;
return perimeter;
}
double getArea(double radious){
double rediousSquare = Math.pow(radious,2);
double area = Math.PI * rediousSquare;
return area;
}
double getArea(double height, double width){
double area = height * width;
return area;
}
double getPerimeter(double height, double width){
double perimeter = 2 * (height + width);
return perimeter;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the serial no for Shape");
System.out.println("1. Circle");
System.out.println("2. Rectangle");
int option = in.nextInt();
if (option == 1) {
System.out.println("Enter the radious");
double radious = in.nextDouble();
Shape circle = new Shape(radious);
double area = circle.getArea(radious);
double perimeter = circle.getPerimeter(radious);
System.out.println("Area of shape is : "+ area +" and perimeter is : " + perimeter);
}
else if (option == 2) {
System.out.println("Enter the height and width");
double height = in.nextDouble();
double width = in.nextDouble();
Shape rectangle = new Shape(height, width);
double area = rectangle.getArea(height, width);
double perimeter = rectangle.getPerimeter(height, width);
System.out.println("Area of shape is : "+ area +" and perimeter is : " + perimeter);
}
else{
System.out.println("Enter valid Option");
}
}
}