Programming Project 2 30 Points Submission ✓ Solved
Programming Project 2 30 Points Submission In
Open Eclipse and create a Java Project called Project2. Add a class named RectangleIntersection to this project. At the top of your file, enter a comment with your name, the assignment number, the date, and a short description of what the program does. When you are finished, export your project from Eclipse and upload it to Canvas before the due date. To do this, right click on the project name and select Export. Select General-â€>Archive File and click Next. Select the project you wish to export (Project2 in this case) and click Browse to browse to a location to save your file. Name this file YourLastNameYourFirstNameProject2. Upload this file to Canvas. Remember that late assignments are not accepted in this course.
Assignment In this project we are going to solve a geometric problem. Geometric problems are important for many applications including data visualization, geographic information systems, integrated circuits, computer graphics, and video games. If boxes are "axis-aligned," meaning the edges are parallel to the x-†and y-â€axes, we can actually figure out whether or not they intersect with some very simple tests. Write a program that prompts the user to enter the center coordinates, widths and heights of two rectangles. Your program should draw the two rectangles to the screen.
If the rectangles do not intersect, they should be colored green. If they do overlap, they should be colored red. How can we tell if the two rectangles overlap? There is a simple and elegant solution. It focuses on when we are sure that there is no overlap. For example, what can we say about the right edge of box 1 and the left edge of box 2? What can we say about the edges now? There are four conditions that guarantee that we have no overlap (two for the left and right edges, two for the top and bottom edges). If any of those conditions are true, that means we do not have an intersection. If none of them are true, it means we have an intersection.
The left and right conditions are illustrated above. Go ahead and draw the top and bottom conditions. I recommend you work in small steps to solve this problem:
- I would approach the problem by first creating variables that represent the centers, widths, and heights of each rectangle and then assigning these variables values within your code.
- I would then write code to draw these rectangles and verify that each rectangle is drawn correctly.
- I would then write code that determines the position of each edge (top, bottom, left, right) of each rectangle.
- Next, I would add the code that checks to see if the rectangles intersect and print out the result (“intersection” or “no intersection”) to the screen.
- I would then color the rectangles appropriately.
- Finally, I would add the user input.
Grading Criteria (30 points possible):
- 0-5 points: Input: Does the program clearly prompt the user for the required values and correctly read in these values from the keyboard?
- 0-10 points: Correctness: Does the program correctly calculate if the two rectangles intersect?
- 0-10 points: Output: Are the rectangles drawn in the proper locations? Are the rectangles drawn with the correct widths and heights? Are they colored properly?
- 0-5 points: Style: Is the code easy to read? Is the code indented in a style similar to that shown in the textbook? Are blank lines used to divide the code into sections? Is a comment with the required information included at the top of the file? Are comments used to provide details that are not obvious? Are meaningful variable names used?