-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot.java
87 lines (68 loc) · 1.77 KB
/
Plot.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package assignment4;
public class Plot {
private int width;
private int depth;
private int x;
private int y;
public Plot() {
x = 0;
y = 0;
width = 1;
depth = 1;
}
public Plot(Plot property) {
x = property.x;
y = property.y;
width = property.width;
depth = property.depth;
}
public Plot(int x, int y, int width, int depth) {
this.x = x;
this.y = y;
this.width = width;
this.depth = depth;
}
public boolean overlaps(Plot plot) {
if (plot.width <= plot.x + (plot.width - plot.x) && this.y <= plot.y + (plot.depth - plot.y)) {
if (plot.depth <= this.x + (this.width - this.x) && plot.y <= this.y + (this.depth - this.y))
return false;
}
return true;
}
public boolean encompasses(Plot plot) {
if (this.x <= plot.x && this.y <= plot.y) {
return true;
}
if (this.depth <= plot.depth && this.width <= plot.width) {
return true;
}
return false;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setWidth(int width) {
this.width = width;
}
public void setDepth(int depth) {
this.depth = depth;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getWidth() {
return width;
}
public int getDepth() {
return depth;
}
public String toString() {
return "Upper left: (" + x + "," + y + "); " + "Width: " + width + " Depth: " + depth;
}
}