forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangles.java
More file actions
21 lines (17 loc) · 754 Bytes
/
Copy pathRectangles.java
File metadata and controls
21 lines (17 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.awt.Rectangle;
public class Rectangles{
public static void main(String[] args){
// special method called a constructor: constructs an object from the class blueprint
Rectangle r1 = new Rectangle(0, 0, 10, 100);
Rectangle r2 = new Rectangle(0, 0, 5, 50);
// does r2 exist within the boundaries of r1?: YES
System.out.println(r1.contains(r2));
// does r1 exist within the bounaries of r2?: NO
System.out.println(r2.contains(r1));
// are r1 and r2 the same rectangle?: NO, they differ in width and height
System.out.println(r1.equals(r2));
Rectangle r3 = new Rectangle(0, 0, 10, 100);
// are r1 and r3 the same rectangle? YES
System.out.println(r1.equals(r3));
}
}