-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
27 lines (20 loc) · 745 Bytes
/
Copy pathMain.java
File metadata and controls
27 lines (20 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import shape.Shape;
import shape.impl.*;
import visitor.ShapeVisitor;
import visitor.impl.Area;
import visitor.impl.Circumference;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Shape> shapes = Arrays.asList(new Circle(10), new Square(10), new Rectangle(10, 2));
ShapeVisitor area = new Area();
ShapeVisitor circumference = new Circumference();
shapes.forEach(shape -> {
shape.accept(area);
System.out.printf("Area of %s is %f\n", shape, area.getValue());
shape.accept(circumference);
System.out.printf("Circumference of %s is %f\n", shape, circumference.getValue());
});
}
}