I'm completely ignorant on JAVA and am currently attempting to learn it. I'm finding it rather confusing. I've googled my question that is on my assignment and it seems that it is a common question. Here it is:
The intersection method computes the intersection of two rectangles, that is the rectangle that is formed by two overlapping rectangles.
You call this method as follows
Rectangle r3 = r1.intersection(r2)
Write a program IntersectionPrinter that constructs two rectangle objects, prints them, and then prints the rectangle object that describes the intersection. Then the program should print the result of the intersection method when the two rectangles do not overlap. Add a comment to your program that explains how you can tell whether the resulting rectangle is empty.
Here's part of my answer:
So, I was able to figure out how to construct the two rectangles, print them, and print the rectangle object that describes the intersection. I'm confused by the next part of the question. If my two rectangles intersect (and in my case, overlap), then how can I print the result of the intersection method when the two rectangles do not overlap? Rectangles cannot simultaneously overlap and not overlap. Have I done something incorrectly? Are they supposed to only intersect and not overlap? If so, how do I go about doing that? Also, please keep in mind that I am only in chapter 2 of my text book and according to my teacher, we are learning the difficult stuff before he will teach us the easy stuff, so if there are shortcuts or easier ways, I probably haven't learned them yet and can't use them on my homework. I hope I have included all the information necessary for someone to help me. Thanks so much for any help given.Code Java:import java.awt.Rectangle; public class InsertionPrinter { public static void main(String[] args) { //construct box1 Rectangle box1 = new Rectangle(0, 0, 20, 40); System.out.println(box1); //label box1 to r1 Rectangle r1 = box1; //construct box2 Rectangle box2 = new Rectangle(10, 20, 40, 60); System.out.println(box2); //label box2 to r2 Rectangle r2 = box2; //calculate intersected region Rectangle r3 = r1.intersection(r2); System.out.println(r3); }}
