Skip to content

Instantly share code, notes, and snippets.

@ifucolo
Created January 28, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifucolo/a7ee49ec1bf97732ab36d1ae94aee8d7 to your computer and use it in GitHub Desktop.
Save ifucolo/a7ee49ec1bf97732ab36d1ae94aee8d7 to your computer and use it in GitHub Desktop.
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