Created
January 28, 2017 17:37
-
-
Save ifucolo/277e5e8f473eadbb91c4141b2a52f4b6 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 Rectangle { | |
private double length; | |
private double height; | |
// getters/setters ... | |
} | |
public class Circle { | |
private double radius; | |
// getters/setters ... | |
} | |
public class AreaFactory { | |
public double calculateArea(ArrayList<Object>... shapes) { | |
double area = 0; | |
for (Object shape : shapes) { | |
if (shape instanceof Rectangle) { | |
Rectangle rect = (Rectangle)shape; | |
area += (rect.getLength() * rect.getHeight()); | |
} else if (shape instanceof Circle) { | |
Circle circle = (Circle)shape; | |
area += | |
(circle.getRadius() * cirlce.getRadius() * Math.PI); | |
} else { | |
throw new RuntimeException("Shape not supported"); | |
} | |
} | |
return area; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment