-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
52 lines (42 loc) · 1.17 KB
/
Copy pathRectangle.java
File metadata and controls
52 lines (42 loc) · 1.17 KB
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
44
45
46
47
48
49
50
51
52
public class Rectangle {
private int sideA;
private int sideB;
private Point topleft;
public Rectangle(int sideA, int sideB, Point topleft) {
this.sideA = sideA; //width
this.sideB = sideB; //height
this.topleft = topleft;
}
public int getSideA() {
return sideA;
}
public void setSideA(int sideA) {
this.sideA = sideA;
}
public int getSideB() {
return sideB;
}
public void setSideB(int sideB) {
this.sideB = sideB;
}
public Point getTopleft() {
return topleft;
}
public void setTopleft(Point topleft) {
this.topleft = topleft;
}
public int area() {
return sideA * sideB;
}
public int perimeter() {
return 2 * (sideA + sideB);
}
public Point[] corners() {
Point[] corners = new Point[4];
corners[0] = topleft;
corners[1] = new Point(topleft.getxCoord() + sideA, topleft.getyCoord());
corners[2] = new Point(topleft.getxCoord() + sideA, topleft.getyCoord() - sideB);
corners[3] = new Point(topleft.getxCoord(), topleft.getyCoord() - sideB);
return corners;
}
}