-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathRectangle.java
More file actions
41 lines (32 loc) · 947 Bytes
/
Rectangle.java
File metadata and controls
41 lines (32 loc) · 947 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
package rectangle;
import java.util.ArrayList;
import java.util.List;
public class Rectangle{
private final int width;
private final int height;
private List<Point> points = new ArrayList<>();
private static final int ARRAY_SIZE = 2;
public Rectangle(List<Integer> inputs) {
init(inputs);
this.width = getWith();
this.height = getHeight();
}
public int getArea() {
return width * height;
}
private void init(List<Integer> inputs) {
for (int pointIndex = 0; pointIndex < inputs.size(); pointIndex++) {
points.add(new Point(inputs.get(pointIndex), inputs.get(++pointIndex)));
}
}
private int getWith() {
return points.get(0).width(points.get(1));
}
private int getHeight() {
return points.get(1).height(points.get(3));
}
@Override
public String toString() {
return points.toString();
}
}