-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawing.java
More file actions
43 lines (30 loc) · 810 Bytes
/
Copy pathDrawing.java
File metadata and controls
43 lines (30 loc) · 810 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package drawing.version1;
import java.util.ArrayList;
import shapes.Circle;
import shapes.Rectangle;
import shapes.Square;
public class Drawing {
private ArrayList<Circle> circles = new ArrayList<Circle>();
private ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>();
private ArrayList<Square> squares = new ArrayList<Square>();
public double calculateTotalArea(){
double totalArea = 0;
for (Circle circle : circles){
totalArea += circle.area();
}
for (Rectangle rect : rectangles){
totalArea += rect.area();
}
for (Square sq : squares){
totalArea += sq.area();
}
return totalArea;
}
public void addCircle(Circle c) {circles.add(c);}
public void addRectangle(Rectangle r) {
rectangles.add(r);
}
public void addSquare(Square s) {
squares.add(s);
}
}