-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonPolygonController.java
More file actions
45 lines (38 loc) · 1.33 KB
/
NonPolygonController.java
File metadata and controls
45 lines (38 loc) · 1.33 KB
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
package com.bee.code.blog.ShapeController;
import com.bee.code.blog.ShapeCommon.ShapeVariableBean;
/**
*
* @author 'beecodeblog
*/
public class NonPolygonController implements AllShapesInterface {
public NonPolygonController() {
}
@Override
public double calculateAreaOfShapes(ShapeVariableBean param, String type) {
double area = 0.0;
if (type.equalsIgnoreCase("CIRCLE")) {
area = calculateAreaOfCircle(param);
} else if (type.equalsIgnoreCase("SPHERE")) {
area = calculateAreaOfSphere(param);
} else {
System.out.println("Sorry, shape not found!!!");
}
return area;
}
// Area of circle= pie *radius *radius
private double calculateAreaOfCircle(ShapeVariableBean param) {
double result = 0.0;
if (param.getRadius() != 0.0) {
result = ShapeVariableBean.PIE_VALUE * param.getRadius() * param.getRadius();
}
return result;
}
//Area of a sphere= 4 * pie *radius * radius
private double calculateAreaOfSphere(ShapeVariableBean param) {
double result = 0.0;
if (param.getRadius() != 0.0) {
result = 4 * ShapeVariableBean.PIE_VALUE * param.getRadius() * param.getRadius();
}
return result;
}
}