diff options
Diffstat (limited to 'sem5/oop/m4/shapes/src/MyCircle.java')
-rw-r--r-- | sem5/oop/m4/shapes/src/MyCircle.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sem5/oop/m4/shapes/src/MyCircle.java b/sem5/oop/m4/shapes/src/MyCircle.java new file mode 100644 index 0000000..45aa4e3 --- /dev/null +++ b/sem5/oop/m4/shapes/src/MyCircle.java @@ -0,0 +1,24 @@ + +public class MyCircle implements Shape2d { + private MyPoint center; + private double r; + + /** + * Creates a 2d circle object + * + * @param center Center of the circle + * @param r Radius of the circle + */ + public MyCircle(MyPoint center, double r) { + this.center = center; + this.r = Math.abs(r); + } + + public double area() { + return Math.PI * this.r * this.r; + } + + public double perimeter() { + return 2 * this.r * Math.PI; + } +} |