Created
February 27, 2019 10:16
-
-
Save egealpay/34da4cddda9c76d67f644826108e8bd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Square { | |
public Point topLeft; | |
public double side; | |
} | |
public class Rectangle { | |
public Point topLeft; | |
public double height; | |
public double width; | |
} | |
public class Circle { | |
public Point center; | |
public double radius; | |
} | |
public class Geometry { | |
public final double PI = 3.141592653589793; | |
public double area(Object shape) throws NoSuchShapeException { | |
if (shape instanceof Square) { | |
Square s = (Square)shape; | |
return s.side * s.side; | |
} | |
else if (shape instanceof Rectangle) { | |
Rectangle r = (Rectangle)shape; | |
return r.height * r.width; | |
} | |
else if (shape instanceof Circle) { | |
Circle c = (Circle)shape; | |
return PI * c.radius * c.radius; | |
} | |
throw new NoSuchShapeException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment