forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleScanner.java
More file actions
37 lines (33 loc) · 1.26 KB
/
Copy pathRectangleScanner.java
File metadata and controls
37 lines (33 loc) · 1.26 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
import java.awt.Rectangle;
import java.util.Scanner;
public class RectangleScanner{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
// System.out.println("Please enter a rectangle width:");
// int width = s.nextInt();
// System.out.println("Please enter a rectangle height:");
// int height = s.nextInt();
// System.out.println("Please enter the upper left x coordinate:");
// int x = s.nextInt();
// System.out.println("Please enter the upper left y coordinate:");
// int y = s.nextInt();
// Rectangle r = new Rectangle(x, y, width, height);
Rectangle r1 = inputRectangle(s);
Rectangle r2 = inputRectangle(s);
Rectangle r3 = r1.intersection(r2);
System.out.println(r1);
System.out.println(r2);
System.out.println(r3);
}
public static Rectangle inputRectangle(Scanner s){
System.out.println("Please enter a rectangle width:");
int width = s.nextInt();
System.out.println("Please enter a rectangle height:");
int height = s.nextInt();
System.out.println("Please enter the upper left x coordinate:");
int x = s.nextInt();
System.out.println("Please enter the upper left y coordinate:");
int y = s.nextInt();
return new Rectangle(x, y, width, height);
}
}