Created
January 28, 2017 17:44
-
-
Save ifucolo/a7ee49ec1bf97732ab36d1ae94aee8d7 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 interface Shape { | |
double getArea(); | |
} | |
public class Rectangle implements Shape{ | |
private double length; | |
private double height; | |
// getters/setters ... | |
@Override | |
public double getArea() { | |
return (length * height); | |
} | |
} | |
public class Circle implements Shape{ | |
private double radius; | |
// getters/setters ... | |
@Override | |
public double getArea() { | |
return (radius * radius * Math.PI); | |
} | |
} | |
public class AreaFactory { | |
public double calculateArea(ArrayList<Shape>... shapes) { | |
double area = 0; | |
for (Shape shape : shapes) { | |
area += shape.getArea(); | |
} | |
return area; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment